Skip to content

Commit

Permalink
fix: retain the batch.Close error
Browse files Browse the repository at this point in the history
  • Loading branch information
yukionfire committed Jul 17, 2024
1 parent 94d685c commit 50f8601
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions store/v2/commitment/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,36 +59,41 @@ func (m *MetadataStore) GetCommitInfo(version uint64) (*proof.CommitInfo, error)
return cInfo, nil
}

func (m *MetadataStore) flushCommitInfo(version uint64, cInfo *proof.CommitInfo) error {
func (m *MetadataStore) flushCommitInfo(version uint64, cInfo *proof.CommitInfo) (err error) {
// do nothing if commit info is nil, as will be the case for an empty, initializing store
if cInfo == nil {
return nil
return
}

batch := m.kv.NewBatch()
defer batch.Close()
defer func() {
cErr := batch.Close()
if err == nil {
err = cErr
}
}()
cInfoKey := []byte(fmt.Sprintf(commitInfoKeyFmt, version))
value, err := cInfo.Marshal()
if err != nil {
return err
return
}
if err := batch.Set(cInfoKey, value); err != nil {
return err
if err = batch.Set(cInfoKey, value); err != nil {
return
}

var buf bytes.Buffer
buf.Grow(encoding.EncodeUvarintSize(version))
if err := encoding.EncodeUvarint(&buf, version); err != nil {
return err
if err = encoding.EncodeUvarint(&buf, version); err != nil {
return
}
if err := batch.Set([]byte(latestVersionKey), buf.Bytes()); err != nil {
return err
if err = batch.Set([]byte(latestVersionKey), buf.Bytes()); err != nil {
return
}

if err := batch.WriteSync(); err != nil {
return err
if err = batch.WriteSync(); err != nil {
return
}
return nil
return
}

func (m *MetadataStore) deleteCommitInfo(version uint64) error {
Expand Down

0 comments on commit 50f8601

Please sign in to comment.