Skip to content

Commit

Permalink
Fix checksum.
Browse files Browse the repository at this point in the history
Signed-off-by: Cody Littley <[email protected]>
  • Loading branch information
cody-littley committed Jul 25, 2024
1 parent 75b160a commit 9972344
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 11 deletions.
2 changes: 1 addition & 1 deletion api/clients/mock/retrieval_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (c *MockRetrievalClient) RetrieveBlobChunks(
batchRoot [32]byte,
quorumID core.QuorumID) (*clients.BlobChunks, error) {

return nil, nil // TODO
return nil, nil
}

func (c *MockRetrievalClient) CombineChunks(chunks *clients.BlobChunks) ([]byte, error) {
Expand Down
5 changes: 5 additions & 0 deletions tools/traffic/blob_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ type BlobMetadata struct {
// checksum of the blob.
checksum *[16]byte

// batchHeaderHash of the blob in bytes.
size uint

// batchHeaderHash of the blob.
batchHeaderHash *[]byte

Expand All @@ -27,13 +30,15 @@ type BlobMetadata struct {
func NewBlobMetadata(
key *[]byte,
checksum *[16]byte,
size uint,
batchHeaderHash *[]byte,
blobIndex uint32,
readPermits int32) *BlobMetadata {

return &BlobMetadata{
key: key,
checksum: checksum,
size: size,
batchHeaderHash: batchHeaderHash,
blobIndex: blobIndex,
remainingReadPermits: readPermits,
Expand Down
11 changes: 5 additions & 6 deletions tools/traffic/blob_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
contractEigenDAServiceManager "github.com/Layr-Labs/eigenda/contracts/bindings/EigenDAServiceManager"
"github.com/Layr-Labs/eigenda/core"
"github.com/Layr-Labs/eigenda/encoding"
"github.com/Layr-Labs/eigenda/encoding/utils/codec"
"github.com/Layr-Labs/eigenda/retriever/eth"
"github.com/Layr-Labs/eigensdk-go/logging"
gcommon "github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -188,7 +187,7 @@ func (reader *BlobReader) randomRead() {
}
reader.recombinationSuccessMetric.Increment()

reader.verifyBlob(metadata, data)
reader.verifyBlob(metadata, &data)

indexSet := make(map[encoding.ChunkNumber]bool)
for index := range chunks.Indices {
Expand Down Expand Up @@ -229,10 +228,10 @@ func (reader *BlobReader) reportMissingChunk(operatorId core.OperatorID) {
}

// verifyBlob performs sanity checks on the blob.
func (reader *BlobReader) verifyBlob(metadata *BlobMetadata, blob []byte) {
recomputedChecksum := md5.Sum(codec.RemoveEmptyByteFromPaddedBytes(blob))

fmt.Printf("metadata.checksum: %x, recomputed checksum: %x\n", *metadata.checksum, recomputedChecksum)
func (reader *BlobReader) verifyBlob(metadata *BlobMetadata, blob *[]byte) {
// Trim off the padding.
truncatedBlob := (*blob)[:metadata.size]
recomputedChecksum := md5.Sum(truncatedBlob)

if *metadata.checksum == recomputedChecksum {
reader.validBlobMetric.Increment()
Expand Down
10 changes: 7 additions & 3 deletions tools/traffic/blob_verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (
type unconfirmedKey struct {
// The key of the blob.
key *[]byte
// The size of the blob in bytes.
size uint
// The checksum of the blob.
checksum *[16]byte
// The time the blob was submitted to the disperser service.
Expand Down Expand Up @@ -96,10 +98,11 @@ func NewStatusVerifier(
}

// AddUnconfirmedKey adds a key to the list of unconfirmed keys.
func (verifier *BlobVerifier) AddUnconfirmedKey(key *[]byte, checksum *[16]byte) {
func (verifier *BlobVerifier) AddUnconfirmedKey(key *[]byte, checksum *[16]byte, size uint) {
verifier.keyChannel <- &unconfirmedKey{
key: key,
checksum: checksum,
size: size,
submissionTime: time.Now(),
}
}
Expand Down Expand Up @@ -131,7 +134,8 @@ func (verifier *BlobVerifier) monitor(period time.Duration) {
// If a key is confirmed, it is added to the blob table and removed from the list of unconfirmed keys.
func (verifier *BlobVerifier) poll() {

// TODO If the number of unconfirmed blobs is high and the time to confirm his high, this is not efficient.
// FUTURE WORK If the number of unconfirmed blobs is high and the time to confirm is high, this is not efficient.
// Revisit this method if there are performance problems.

unconfirmedKeys := make([]*unconfirmedKey, 0)
for _, key := range verifier.unconfirmedKeys {
Expand Down Expand Up @@ -226,6 +230,6 @@ func (verifier *BlobVerifier) forwardToReader(key *unconfirmedKey, status *dispe
downloadCount = int32(requiredDownloads)
}

blobMetadata := NewBlobMetadata(key.key, key.checksum, &batchHeaderHash, blobIndex, downloadCount)
blobMetadata := NewBlobMetadata(key.key, key.checksum, key.size, &batchHeaderHash, blobIndex, downloadCount)
verifier.table.Add(blobMetadata)
}
4 changes: 3 additions & 1 deletion tools/traffic/blob_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,10 @@ func (writer *BlobWriter) run() {

writer.writeSuccessMetric.Increment()

fmt.Printf(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Data size = %d\n", len(*data))

checksum := md5.Sum(*data)
writer.verifier.AddUnconfirmedKey(&key, &checksum)
writer.verifier.AddUnconfirmedKey(&key, &checksum, uint(len(*data)))
}
}
}
Expand Down

0 comments on commit 9972344

Please sign in to comment.