Skip to content
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

feat: Use ListOffChainData instead of GetOffChainData #152

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 26 additions & 31 deletions dataavailability/datacommittee/datacommittee.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,28 +107,16 @@ func (d *Backend) Init() error {

// GetSequence gets backend data one hash at a time. This should be optimized on the DAC side to get them all at once.
func (d *Backend) GetSequence(_ context.Context, hashes []common.Hash, _ []byte) ([][]byte, error) {
// TODO: optimize this on the DAC side by implementing a multi batch retrieve api)
batchData := make([][]byte, 0, len(hashes))
for _, h := range hashes {
data, err := d.GetBatchL2Data(h)
if err != nil {
return nil, err
}
batchData = append(batchData, data)
}

return batchData, nil
}

// GetBatchL2Data returns the data from the DAC. It checks that it matches with the expected hash
func (d *Backend) GetBatchL2Data(hash common.Hash) ([]byte, error) {
intialMember := d.selectedCommitteeMember
found := false

var found bool
for !found && intialMember != -1 {
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)
data, err := c.GetOffChainData(d.ctx, hash)

dataMap, err := c.ListOffChainData(d.ctx, hashes)
if err != nil {
d.logger.Warnf(
"error getting data from DAC node %s at %s: %s",
Expand All @@ -141,25 +129,32 @@ func (d *Backend) GetBatchL2Data(hash common.Hash) ([]byte, error) {

continue
}
actualTransactionsHash := crypto.Keccak256Hash(data)
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,
)
d.selectedCommitteeMember = (d.selectedCommitteeMember + 1) % len(d.committeeMembers)
if d.selectedCommitteeMember == intialMember {
break

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,
)
d.selectedCommitteeMember = (d.selectedCommitteeMember + 1) % len(d.committeeMembers)
if d.selectedCommitteeMember == intialMember {
break
}

continue
}

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

return data, nil
return batchData, nil
}

if err := d.Init(); err != nil {
return nil, fmt.Errorf("error loading data committee: %w", err)
}
Expand Down
Loading