diff --git a/PENDING.md b/PENDING.md index b3885942b9bc..7a4f32a62b9a 100644 --- a/PENDING.md +++ b/PENDING.md @@ -52,7 +52,8 @@ IMPROVEMENTS - \#2660 [x/mock/simulation] Staking transactions get tested far more frequently - \#2610 [x/stake] Block redelegation to and from the same validator - \#2652 [x/auth] Add benchmark for get and set account - - \#2685 [x/store] Add general merkle absence proof (also for empty substores) + - \#2685 [store] Add general merkle absence proof (also for empty substores) + - \#2708 [store] Disallow setting nil values * Tendermint diff --git a/store/cachekvstore.go b/store/cachekvstore.go index 9eb4ae9324db..4a2940f4df41 100644 --- a/store/cachekvstore.go +++ b/store/cachekvstore.go @@ -61,6 +61,7 @@ func (ci *cacheKVStore) Set(key []byte, value []byte) { ci.mtx.Lock() defer ci.mtx.Unlock() ci.assertValidKey(key) + ci.assertValidValue(value) ci.setCacheValue(key, value, false, true) } @@ -196,6 +197,12 @@ func (ci *cacheKVStore) assertValidKey(key []byte) { } } +func (ci *cacheKVStore) assertValidValue(value []byte) { + if value == nil { + panic("value is nil") + } +} + // Only entrypoint to mutate ci.cache. func (ci *cacheKVStore) setCacheValue(key, value []byte, deleted bool, dirty bool) { ci.cache[string(key)] = cValue{ diff --git a/types/store.go b/types/store.go index 7bab93b97e60..a90dc223dd50 100644 --- a/types/store.go +++ b/types/store.go @@ -127,7 +127,7 @@ type KVStore interface { // Has checks if a key exists. Panics on nil key. Has(key []byte) bool - // Set sets the key. Panics on nil key. + // Set sets the key. Panics on nil key or value. Set(key, value []byte) // Delete deletes the key. Panics on nil key.