@@ -34,47 +34,48 @@ func (k Keeper) setBatch(ctx context.Context, batch types.Batch) error {
3434 return k .batches .Set (ctx , batch .BlockHeight , batch )
3535}
3636
37- // SetNewBatch increments the current batch number and stores a given
38- // batch at that index. It also stores the given data result tree
39- // entries, validator tree entries, and batch signature entries (at
40- // the next batch index, to be populated with signatures later). It
41- // returns an error if a batch already exists at the given batch's
42- // block height or if the given batch's batch number does not match
43- // the next batch number.
44- func (k Keeper ) SetNewBatch (ctx context.Context , batch types.Batch , dataEntries types.DataResultTreeEntries , valEntries []types.ValidatorTreeEntry ) error {
37+ // SetNewBatch stores a new batch and its associated data at current batch number
38+ // and increments the current batch number. If successful, it returns the batch number
39+ // of the newly created batch.
40+ func (k Keeper ) SetNewBatch (ctx sdk.Context , batch types.Batch , dataEntries types.DataResultTreeEntries , valEntries []types.ValidatorTreeEntry ) (uint64 , error ) {
4541 found , err := k .batches .Has (ctx , batch .BlockHeight )
4642 if err != nil {
47- return err
43+ return 0 , err
4844 }
4945 if found {
50- return types .ErrBatchAlreadyExists .Wrapf ("batch block height %d" , batch .BlockHeight )
46+ return 0 , types .ErrBatchAlreadyExists .Wrapf ("batch block height %d" , batch .BlockHeight )
5147 }
5248
5349 batchNum , err := k .GetCurrentBatchNum (ctx )
5450 if err != nil {
55- return err
51+ return 0 , err
5652 }
5753 if batch .BatchNumber != batchNum {
58- return types .ErrInvalidBatchNumber .Wrapf ("got %d; expected %d" , batch .BatchNumber , batchNum )
54+ return 0 , types .ErrInvalidBatchNumber .Wrapf ("got %d; expected %d" , batch .BatchNumber , batchNum )
5955 }
6056
6157 err = k .setDataResultTreeEntry (ctx , batchNum , dataEntries )
6258 if err != nil {
63- return err
59+ return 0 , err
6460 }
6561
6662 for _ , valEntry := range valEntries {
6763 err = k .setValidatorTreeEntry (ctx , batchNum , valEntry )
6864 if err != nil {
69- return err
65+ return 0 , err
7066 }
7167 }
7268
7369 _ , err = k .incrementCurrentBatchNum (ctx )
7470 if err != nil {
75- return err
71+ return 0 , err
7672 }
77- return k .batches .Set (ctx , batch .BlockHeight , batch )
73+
74+ err = k .batches .Set (ctx , batch .BlockHeight , batch )
75+ if err != nil {
76+ return 0 , err
77+ }
78+ return batchNum , nil
7879}
7980
8081func (k Keeper ) GetBatchForHeight (ctx context.Context , blockHeight int64 ) (types.Batch , error ) {
0 commit comments