-
Notifications
You must be signed in to change notification settings - Fork 553
eth: implemented peer consensus based witness verification #1766
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
base: develop
Are you sure you want to change the base?
Conversation
eth/handler_eth.go
Outdated
if witPacket, ok := res.Res.(*wit.WitnessPacketRLPPacket); ok && len(witPacket.WitnessPacketResponse) > 0 { | ||
return witPacket.WitnessPacketResponse[0].TotalPages, nil | ||
} |
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.
The res
from resCh
is not *wit.WitnessPacketRLPPacket
but actually []*stateless.Witness
.
Reference:
Lines 256 to 276 in 8c7fa04
var witnesses []*stateless.Witness | |
var responseHashes []common.Hash | |
for hash, wit := range reconstructedWitness { | |
witnesses = append(witnesses, wit) | |
responseHashes = append(responseHashes, hash) | |
} | |
if len(witnesses) != len(hashes) { | |
p.witPeer.Peer.Log().Error("Not able to fetch all requests witnesses", "peer", p.ID(), "requestedHashes", hashes, "responseHashes", responseHashes) | |
} | |
doneCh := make(chan error) | |
go func() { | |
<-doneCh | |
}() | |
// Adapt wit.Response[] to eth.Response. | |
// We can only copy exported fields. The unexported fields (id, recv, code) | |
// will have zero values in the ethRes sent to the caller. | |
// Correlation still works via the Req field. | |
ethRes := ð.Response{ | |
Req: wrapperReq.Request, // Point back to the embedded shim request. | |
Res: witnesses, |
A few things we should consider:
- By requesting that way, we are downloading the whole witness, not a single page. (In this case
>160MB
) - Even requesting a single page, still a big amount of data (
16MB
for each peer) - We should consider implementing a new method to just retrieve the page count. (may be useful for future scenarios)
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.
Thanks Lucca, makes sense
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.
does this makes sense?
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.
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.
Hi @pratikspatil024 , good question. Introducing a new method allows us reducing from 16MB in this packet to basically 0. So it seems like an interesting upgrade. We can maybe deliver this first version that way but keep the upgrade on backlog.
Since this isn't a necessary feature in the initial veblop release, let's use |
core/stateless/witness_test.go
Outdated
func TestWitnessVerificationConstants(t *testing.T) { | ||
// These constants should match the ones defined in eth/fetcher/witness_manager.go | ||
const ( | ||
witnessPageWarningThreshold = 10 |
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.
Might be better to make this a dynamic parameter based on the block gas limit.
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.
done.
46a08b6
to
9515bd1
Compare
…s between 3 peers
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.
Has this been tested in a devnet? It would be great if we can create some test scenarios for this new logic.
eth/handler_eth.go
Outdated
// Request witnesses using the wit peer | ||
return ethPeer.RequestWitnesses([]common.Hash{hash}, sink) | ||
// Create verification callback for page count verification (returns true if honest) | ||
verifyPageCount := func(hash common.Hash, pageCount uint64, peer string) bool { |
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.
Could this be moved to a standalone function instead of being an embedded function?
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.
Moved, thanks!
eth/peer.go
Outdated
mapsMu.Lock() | ||
downloadPaused[page.Hash] = true | ||
mapsMu.Unlock() | ||
p.witPeer.Peer.Log().Warn("Peer failed verification, pausing witness download", "peer", p.ID(), "hash", page.Hash, "totalPages", page.TotalPages) |
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.
Should the node drop a peer here if the peer is dishonest? The block hash is added to downloadPaused
but no further action is taken it seems.
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.
Nice catch! Fixed, thanks!
eth/handler_eth.go
Outdated
} | ||
|
||
// Run synchronous verification and return result | ||
return h.blockFetcher.GetWitnessManager().CheckWitnessPageCount(hash, pageCount, peer, getRandomPeers, getWitnessPageCount) |
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.
Should we call CheckWitnessPageCount
first before sampling from peers? Because it would avoid sending unnecessary metadata request to peers in most cases.
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.
This is what's happening right now, the getRandomPeers
function is used at a later point. Added comments.
Let me know if this is not what you meant, thanks!
|
Description
Implemented peer consensus based witness verification
Verification Flow:
Changes
Breaking changes
Please complete this section if any breaking changes have been made, otherwise delete it
Nodes audience
In case this PR includes changes that must be applied only to a subset of nodes, please specify how you handled it (e.g. by adding a flag with a default value...)
Checklist
Cross repository changes
Testing
Manual tests
Please complete this section with the steps you performed if you ran manual tests for this functionality, otherwise delete it
Additional comments
Please post additional comments in this section if you have them, otherwise delete it