From 282d2ad3c51429eee7a8ac04593d1bc7b4e0bc03 Mon Sep 17 00:00:00 2001 From: dhrubabasu <7675102+dhrubabasu@users.noreply.github.com> Date: Thu, 20 Jun 2024 09:01:04 -0700 Subject: [PATCH 1/2] [chains/atomic] Remove a nested if statement --- chains/atomic/state.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/chains/atomic/state.go b/chains/atomic/state.go index 1eed23803fb..9899ccd8681 100644 --- a/chains/atomic/state.go +++ b/chains/atomic/state.go @@ -147,12 +147,7 @@ func (s *state) SetValue(e *Element) error { // current engine state. func (s *state) RemoveValue(key []byte) error { value, err := s.loadValue(key) - if err != nil { - if err != database.ErrNotFound { - // An unexpected error occurred, so we should propagate that error - return err - } - + if err == database.ErrNotFound { // The value doesn't exist, so we should optimistically delete it dbElem := dbElement{Present: false} valueBytes, err := Codec.Marshal(CodecVersion, &dbElem) @@ -161,6 +156,10 @@ func (s *state) RemoveValue(key []byte) error { } return s.valueDB.Put(key, valueBytes) } + if err != nil { + // An unexpected error occurred, so we should propagate that error + return err + } // Don't allow the removal of something that was already removed. if !value.Present { From 415a062dcec41e173c46a81f0a362bb11d13c9ba Mon Sep 17 00:00:00 2001 From: Dhruba Basu <7675102+dhrubabasu@users.noreply.github.com> Date: Thu, 20 Jun 2024 09:14:06 -0700 Subject: [PATCH 2/2] Update chains/atomic/state.go Signed-off-by: Dhruba Basu <7675102+dhrubabasu@users.noreply.github.com> --- chains/atomic/state.go | 1 - 1 file changed, 1 deletion(-) diff --git a/chains/atomic/state.go b/chains/atomic/state.go index 9899ccd8681..b134d2f7a5d 100644 --- a/chains/atomic/state.go +++ b/chains/atomic/state.go @@ -157,7 +157,6 @@ func (s *state) RemoveValue(key []byte) error { return s.valueDB.Put(key, valueBytes) } if err != nil { - // An unexpected error occurred, so we should propagate that error return err }