Skip to content

Commit

Permalink
state: Save now defers v.tx.Unlock() until the end
Browse files Browse the repository at this point in the history
  • Loading branch information
altergui committed Sep 19, 2023
1 parent 33dd3ea commit 15aa0de
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion vochain/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ func (v *State) Save() ([]byte, error) {
// Note that we need to commit the tx after calling listeners, because
// the listeners may need to get the previous (not committed) state.
v.tx.Lock()
defer v.tx.Unlock()
err := func() error {
var err error
if err := v.tx.Commit(height); err != nil {
Expand All @@ -414,7 +415,6 @@ func (v *State) Save() ([]byte, error) {
}
return nil
}()
v.tx.Unlock()
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 15aa0de

Please sign in to comment.