Skip to content

Commit

Permalink
refact: GetSequence method
Browse files Browse the repository at this point in the history
  • Loading branch information
rachit77 committed Nov 7, 2024
1 parent d7d9947 commit 5180ba2
Showing 1 changed file with 10 additions and 23 deletions.
33 changes: 10 additions & 23 deletions dataavailability/datacommittee/datacommittee.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,53 +105,40 @@ func (d *Backend) Init() error {
return nil
}

// GetSequence gets backend data one hash at a time. This should be optimized on the DAC side to get them all at once.
// GetSequence retrieves backend data by querying committee members for each hash concurrently.
func (d *Backend) GetSequence(_ context.Context, hashes []common.Hash, _ []byte) ([][]byte, error) {
intialMember := d.selectedCommitteeMember
initialMember := d.selectedCommitteeMember

var found bool
for !found && intialMember != -1 {
var batchData [][]byte
for retries := 0; retries < len(d.committeeMembers); retries++ {
member := d.committeeMembers[d.selectedCommitteeMember]
d.logger.Infof("trying to get data from %s at %s", member.Addr.Hex(), member.URL)

c := d.dataCommitteeClientFactory.New(member.URL)

dataMap, err := c.ListOffChainData(d.ctx, hashes)
if err != nil {
d.logger.Warnf(
"error getting data from DAC node %s at %s: %s",
member.Addr.Hex(), member.URL, err,
)
d.logger.Warnf("error getting data from DAC node %s at %s: %s", member.Addr.Hex(), member.URL, err)
d.selectedCommitteeMember = (d.selectedCommitteeMember + 1) % len(d.committeeMembers)
if d.selectedCommitteeMember == intialMember {
if d.selectedCommitteeMember == initialMember {
break
}

continue
}

batchData := make([][]byte, 0, len(hashes))
batchData = make([][]byte, 0, len(hashes))
for _, hash := range hashes {
actualTransactionsHash := crypto.Keccak256Hash(dataMap[hash])
if actualTransactionsHash != hash {
unexpectedHash := fmt.Errorf(
unexpectedHashTemplate, hash, actualTransactionsHash,
)
d.logger.Warnf(
"error getting data from DAC node %s at %s: %s",
member.Addr.Hex(), member.URL, unexpectedHash,
)
unexpectedHash := fmt.Errorf(unexpectedHashTemplate, hash, actualTransactionsHash)
d.logger.Warnf("error getting data from DAC node %s at %s: %s", member.Addr.Hex(), member.URL, unexpectedHash)
d.selectedCommitteeMember = (d.selectedCommitteeMember + 1) % len(d.committeeMembers)
if d.selectedCommitteeMember == intialMember {
if d.selectedCommitteeMember == initialMember {
break
}

continue
}

batchData = append(batchData, dataMap[hash])
}

return batchData, nil
}

Expand Down

0 comments on commit 5180ba2

Please sign in to comment.