Skip to content

Commit

Permalink
Simplify minibatch data model (#707)
Browse files Browse the repository at this point in the history
  • Loading branch information
ian-shim authored Aug 20, 2024
1 parent e4af079 commit dbeaf12
Show file tree
Hide file tree
Showing 10 changed files with 466 additions and 974 deletions.
17 changes: 8 additions & 9 deletions disperser/batcher/batch_confirmer.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,23 +312,18 @@ func (b *BatchConfirmer) HandleSingleBatch(ctx context.Context) error {
b.logger.Debug("Getting latest formed batch...")
stateUpdateTicker := time.NewTicker(b.DispersalStatusCheckInterval)
var batch *BatchRecord
var minibatches []*MinibatchRecord
for batch == nil {
select {
case <-ctx.Done():
return ctx.Err()
case <-stateUpdateTicker.C:
batch, minibatches, err = b.MinibatchStore.GetLatestFormedBatch(ctx)
batch, err = b.MinibatchStore.GetLatestFormedBatch(ctx)
if err != nil {
b.logger.Error("error getting latest formed batch", "err", err)
}
}
}

if len(minibatches) == 0 {
return fmt.Errorf("no minibatches in the batch %s", batch.ID)
}

// Make sure all minibatches in the batch have been dispersed
batchDispersed := false
stateUpdateTicker.Reset(b.DispersalStatusCheckInterval)
Expand All @@ -339,7 +334,7 @@ func (b *BatchConfirmer) HandleSingleBatch(ctx context.Context) error {
case <-ctxWithTimeout.Done():
return ctxWithTimeout.Err()
case <-stateUpdateTicker.C:
batchDispersed, err = b.MinibatchStore.BatchDispersed(ctx, batch.ID)
batchDispersed, err = b.MinibatchStore.BatchDispersed(ctx, batch.ID, batch.NumMinibatches)
if err != nil {
b.logger.Error("error checking if batch is dispersed", "err", err)
}
Expand All @@ -364,8 +359,12 @@ func (b *BatchConfirmer) HandleSingleBatch(ctx context.Context) error {
BatchRoot: [32]byte{},
}
blobHeaderHashes := make([][32]byte, 0)
for _, minibatch := range minibatches {
blobHeaderHashes = append(blobHeaderHashes, minibatch.BlobHeaderHashes...)
for _, blobHeader := range batchState.BlobHeaders {
blobHeaderHash, err := blobHeader.GetBlobHeaderHash()
if err != nil {
return fmt.Errorf("error getting blob header hash: %w", err)
}
blobHeaderHashes = append(blobHeaderHashes, blobHeaderHash)
}
merkleTree, err := batchHeader.SetBatchRootFromBlobHeaderHashes(blobHeaderHashes)
if err != nil {
Expand Down
Loading

0 comments on commit dbeaf12

Please sign in to comment.