File tree Expand file tree Collapse file tree 3 files changed +15
-7
lines changed
.changelog/unreleased/bug-fixes
core/src/ledger/storage_api/collections Expand file tree Collapse file tree 3 files changed +15
-7
lines changed Original file line number Diff line number Diff line change 1+ - Avoid redundant storage deletions in lazy collections that would incur
2+ extra gas cause and appear in transaction result as changed keys even if not
3+ changed occurred. This may have caused PoS transactions to run out of gas.
4+ ([ \# 1984] ( https://github.com/anoma/namada/pull/1984 ) )
Original file line number Diff line number Diff line change @@ -585,16 +585,18 @@ where
585585 Ok ( previous)
586586 }
587587
588- /// Removes a key from the map, returning the value at the key if the key
589- /// was previously in the map.
588+ /// Removes a key from the map if it's present , returning the value at the
589+ /// key if the key was previously in the map.
590590 pub fn remove < S > ( & self , storage : & mut S , key : & K ) -> Result < Option < V > >
591591 where
592592 S : StorageWrite + StorageRead ,
593593 {
594594 let value = self . get ( storage, key) ?;
595595
596- let data_key = self . get_data_key ( key) ;
597- storage. delete ( & data_key) ?;
596+ if value. is_some ( ) {
597+ let data_key = self . get_data_key ( key) ;
598+ storage. delete ( & data_key) ?;
599+ }
598600
599601 Ok ( value)
600602 }
Original file line number Diff line number Diff line change @@ -183,16 +183,18 @@ where
183183 storage. write ( & key, ( ) )
184184 }
185185
186- /// Removes a key from the set, returning `true` if the key
186+ /// Removes a key from the set if it's present , returning `true` if the key
187187 /// was in the set.
188188 pub fn remove < S > ( & self , storage : & mut S , key : & K ) -> Result < bool >
189189 where
190190 S : StorageWrite + StorageRead ,
191191 {
192192 let present = self . contains ( storage, key) ?;
193193
194- let key = self . get_key ( key) ;
195- storage. delete ( & key) ?;
194+ if present {
195+ let key = self . get_key ( key) ;
196+ storage. delete ( & key) ?;
197+ }
196198
197199 Ok ( present)
198200 }
You can’t perform that action at this time.
0 commit comments