-
Notifications
You must be signed in to change notification settings - Fork 139
Closed
Labels
StaleT:enhancementType: Enhancement, New feature or requestType: Enhancement, New feature or request
Description
We have to make sure, that keys will not collide when different prefixes are used. When setting or getting a value from the db, the keys are simply appended:
https://github.com/tendermint/tendermint/blob/40d6dc2ee55a34a075e7b7e73c3525c84ae705ea/libs/db/prefix_db.go#L228-L230
This leads to the following behaviour (a value of the namespace "prefix-key" can be accessed from 2 different prefix dbs):
package main
import tdb "github.com/tendermint/tendermint/libs/db"
import "fmt"
func bz(v string) []byte {
return []byte(v)
}
func main() {
db := tdb.NewMemDB()
db.Set(bz("prefix-key"), bz("100"))
pdb1 := tdb.NewPrefixDB(db, bz("prefix-"))
fmt.Printf("%s\n",pdb1.Get(bz("key")))
pdb2 := tdb.NewPrefixDB(db, bz("pre"))
fmt.Printf("%s\n",pdb2.Get(bz("fix-key")))
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
StaleT:enhancementType: Enhancement, New feature or requestType: Enhancement, New feature or request