From 0c78434322791edb27d512680dafca5fcf323692 Mon Sep 17 00:00:00 2001 From: egonspace Date: Fri, 21 May 2021 14:45:25 +0900 Subject: [PATCH] chore: add comment about concurrency of cache functions --- x/params/types/subspace.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/x/params/types/subspace.go b/x/params/types/subspace.go index 598aad703e..2f5943a627 100644 --- a/x/params/types/subspace.go +++ b/x/params/types/subspace.go @@ -181,6 +181,14 @@ func (s *Subspace) checkType(key []byte, value interface{}) { } } +// All the cache-related functions here are thread-safe. +// Currently, since `CheckTx` and `DeliverTx` can run without abci locking, +// these functions must be thread-safe as tx can run concurrently. +// The map data type is not thread-safe by itself, but concurrent access is +// possible with entry fixed. If we access the subspace with an unregistered key, +// it panics, ensuring that the entry of the map is not extended after the server runs. +// Value update and read operations for a single entry of a map can be performed concurrently by +// `atomic.StorePointer` and `atomic.LoadPointer`. func (s *Subspace) cacheValue(key []byte, value interface{}) { attr, ok := s.table.m[string(key)] if !ok {