sync blobs in initial-sync (#12522)

This commit is contained in:
kasey
2023-07-25 16:57:01 -05:00
committed by Preston Van Loon
parent 48f1f69695
commit 3476112d63
32 changed files with 1163 additions and 368 deletions

View File

@@ -5,6 +5,7 @@ import (
"sort"
"github.com/prysmaticlabs/prysm/v4/consensus-types/interfaces"
eth "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1"
)
// ROBlock is a value that embeds a ReadOnlySignedBeaconBlock along with its block root ([32]byte).
@@ -73,3 +74,44 @@ func (s ROBlockSlice) Swap(i, j int) {
func (s ROBlockSlice) Len() int {
return len(s)
}
type BlockWithVerifiedBlobs struct {
Block ROBlock
Blobs []*eth.BlobSidecar
}
type BlockWithVerifiedBlobsSlice []BlockWithVerifiedBlobs
func (s BlockWithVerifiedBlobsSlice) ROBlocks() []ROBlock {
r := make([]ROBlock, len(s))
for i := range s {
r[i] = s[i].Block
}
return r
}
// Less reports whether the element with index i must sort before the element with index j.
// ROBlocks are ordered first by their slot,
// with a lexicographic sort of roots breaking ties for slots with duplicate blocks.
func (s BlockWithVerifiedBlobsSlice) Less(i, j int) bool {
si, sj := s[i].Block.Block().Slot(), s[j].Block.Block().Slot()
// lower slot wins
if si != sj {
return si < sj
}
// break slot tie lexicographically comparing roots byte for byte
ri, rj := s[i].Block.Root(), s[j].Block.Root()
return bytes.Compare(ri[:], rj[:]) < 0
}
// Swap swaps the elements with indexes i and j.
func (s BlockWithVerifiedBlobsSlice) Swap(i, j int) {
s[i], s[j] = s[j], s[i]
}
// Len is the number of elements in the collection.
func (s BlockWithVerifiedBlobsSlice) Len() int {
return len(s)
}