From e96d433d012fe022c7eb9c3bd7a49d1f402a96c1 Mon Sep 17 00:00:00 2001 From: pistomat Date: Thu, 14 Nov 2024 11:36:57 +0100 Subject: [PATCH] fix: Iterate pendingWrites backward to get the last updated value (#285) fix: Iterate pendingWrites backward to get the latest update --- suave/cstore/transactional_store.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/suave/cstore/transactional_store.go b/suave/cstore/transactional_store.go index 4e0bfc088..2cc7558b9 100644 --- a/suave/cstore/transactional_store.go +++ b/suave/cstore/transactional_store.go @@ -82,7 +82,8 @@ func (s *TransactionalStore) Retrieve(dataId suave.DataId, caller common.Address s.pendingLock.Lock() - for _, sw := range s.pendingWrites { + for i := len(s.pendingWrites) - 1; i >= 0; i-- { + sw := s.pendingWrites[i] if sw.DataRecord.Id == record.Id && sw.Key == key { s.pendingLock.Unlock() return common.CopyBytes(sw.Value), nil