-
Notifications
You must be signed in to change notification settings - Fork 237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add PruningPointProof to the P2P protocol #1825
Merged
someone235
merged 15 commits into
kaspanet:v0.11.0-dev
from
stasatdaglabs:pruning-point-proof
Sep 5, 2021
Merged
Changes from 8 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
393e154
Add PruningPointProof to externalapi.
stasatdaglabs bdeb954
Add BuildPruningPointProof and ValidatePruningPointProof to Consensus.
stasatdaglabs de36396
Add the pruning point proof to the protocol.
stasatdaglabs 1a66498
Add the pruning point proof to the wire package.
stasatdaglabs 48182f6
Add PruningPointBlueWork.
stasatdaglabs 59a34c4
Make go vet happy.
stasatdaglabs 9391574
Properly initialize PruningPointProof in consensus.go.
stasatdaglabs c6a90c5
Validate pruning point blue work.
stasatdaglabs f2a9829
Populate PruningPointBlueWork with the actual blue work of the prunin…
stasatdaglabs 94d899a
Revert "Populate PruningPointBlueWork with the actual blue work of th…
stasatdaglabs d1a9f26
Revert "Validate pruning point blue work."
stasatdaglabs b169608
Revert "Properly initialize PruningPointProof in consensus.go."
stasatdaglabs b1c06e3
Revert "Add PruningPointBlueWork."
stasatdaglabs 667b6e9
Fix PruningPointProof and MsgPruningPointProof to be two-dimensional.
stasatdaglabs 984aad7
Fix wire PruningPointProof to be two-dimensional.
stasatdaglabs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,24 @@ | ||
package appmessage | ||
|
||
import "math/big" | ||
|
||
// MsgPruningPointProof represents a kaspa PruningPointProof message | ||
type MsgPruningPointProof struct { | ||
baseMessage | ||
|
||
Headers []*MsgBlockHeader | ||
PruningPointBlueWork *big.Int | ||
} | ||
|
||
// Command returns the protocol command string for the message | ||
func (msg *MsgPruningPointProof) Command() MessageCommand { | ||
return CmdPruningPointProof | ||
} | ||
|
||
// NewMsgPruningPointProof returns a new MsgPruningPointProof. | ||
func NewMsgPruningPointProof(headers []*MsgBlockHeader, pruningPointBlueWork *big.Int) *MsgPruningPointProof { | ||
return &MsgPruningPointProof{ | ||
Headers: headers, | ||
PruningPointBlueWork: pruningPointBlueWork, | ||
} | ||
} |
File renamed without changes.
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,16 @@ | ||
package appmessage | ||
|
||
// MsgRequestPruningPointProof represents a kaspa RequestPruningPointProof message | ||
type MsgRequestPruningPointProof struct { | ||
baseMessage | ||
} | ||
|
||
// Command returns the protocol command string for the message | ||
func (msg *MsgRequestPruningPointProof) Command() MessageCommand { | ||
return CmdRequestPruningPointProof | ||
} | ||
|
||
// NewMsgRequestPruningPointProof returns a new MsgRequestPruningPointProof. | ||
func NewMsgRequestPruningPointProof() *MsgRequestPruningPointProof { | ||
return &MsgRequestPruningPointProof{} | ||
} |
40 changes: 40 additions & 0 deletions
40
app/protocol/flows/blockrelay/handle_pruning_point_proof_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,40 @@ | ||
package blockrelay | ||
|
||
import ( | ||
"github.com/kaspanet/kaspad/app/appmessage" | ||
peerpkg "github.com/kaspanet/kaspad/app/protocol/peer" | ||
"github.com/kaspanet/kaspad/domain" | ||
"github.com/kaspanet/kaspad/infrastructure/network/netadapter/router" | ||
) | ||
|
||
// PruningPointProofRequestsContext is the interface for the context needed for the HandlePruningPointProofRequests flow. | ||
type PruningPointProofRequestsContext interface { | ||
Domain() domain.Domain | ||
} | ||
|
||
// HandlePruningPointProofRequests listens to appmessage.MsgRequestPruningPointProof messages and sends | ||
// the pruning point proof to the requesting peer. | ||
func HandlePruningPointProofRequests(context PruningPointProofRequestsContext, incomingRoute *router.Route, | ||
outgoingRoute *router.Route, peer *peerpkg.Peer) error { | ||
|
||
for { | ||
_, err := incomingRoute.Dequeue() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
log.Debugf("Got request for pruning point proof from %s", peer) | ||
|
||
pruningPointProof, err := context.Domain().Consensus().BuildPruningPointProof() | ||
if err != nil { | ||
return err | ||
} | ||
pruningPointProofMessage := appmessage.DomainPruningPointProofToMsgPruningPointProof(pruningPointProof) | ||
err = outgoingRoute.Enqueue(pruningPointProofMessage) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
log.Debugf("Sent pruning point proof to %s", peer) | ||
} | ||
} |
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 |
---|---|---|
|
@@ -722,3 +722,20 @@ func (s *consensus) ResolveVirtual() error { | |
} | ||
} | ||
} | ||
|
||
func (s *consensus) BuildPruningPointProof() (*externalapi.PruningPointProof, error) { | ||
s.lock.Lock() | ||
defer s.lock.Unlock() | ||
|
||
return &externalapi.PruningPointProof{ | ||
Headers: []externalapi.BlockHeader{}, | ||
PruningPointBlueWork: big.NewInt(0), | ||
}, nil | ||
} | ||
|
||
func (s *consensus) ValidatePruningPointProof(pruningPointProof *externalapi.PruningPointProof) error { | ||
s.lock.Lock() | ||
defer s.lock.Unlock() | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add a TODO? |
||
return nil | ||
} |
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,9 @@ | ||
package externalapi | ||
|
||
import "math/big" | ||
|
||
// PruningPointProof is the data structure holding the pruning point proof | ||
type PruningPointProof struct { | ||
Headers []BlockHeader | ||
PruningPointBlueWork *big.Int | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a TODO?