-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cleanup storage #185
Cleanup storage #185
Conversation
9088c5a
to
cf472e6
Compare
app/store.go
Outdated
// Expand the path fully | ||
dbPath, err := filepath.Abs(dbName) | ||
if err != nil { | ||
panic(fmt.Sprintf("Invalid Database Name: %s", dbName)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So for a package function, wouldn't it be better if instead we returned an error instead of surprisingly panicking in the code so
func NewStore(dbName string, cacheSize int, logger log.Logger) (*Store, error)
otherwise the function itself has no mention that it'll panic if we can't expand the path. IMHO if we want to panic, maybe make another function say
func MustMakeNewStore(dbName string, cacheSize int, logger log.Logger) *Store
and then from there one can panic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Totally agree...
This code was adapted from another package. Basically all the parsing code copied.
There are way too many panics all over our codebase... and after fighting against them for a while I get lazy. Thanks for pushing me to do this properly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gotcha, I've encountered this quite often too when adapting code from different packages. For sure, you've extra hands here and we'll fight these panics 🙏 #panicBusters
app/store.go
Outdated
} | ||
|
||
// CloseDB closes the database | ||
// func (s *Store) CloseDB() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you mean to leave this commented out?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was never really called anywhere, so I guess it can be removed. I'll delete it fully.
state/chainstate.go
Outdated
// SetChainID stores the chain id in the store | ||
func (s *ChainState) SetChainID(store KVStore, chainID string) { | ||
s.chainID = chainID | ||
store.Set([]byte("base/chain_id"), []byte(chainID)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's lift this out of here and instead make it a variable
var baseChainIDKey = []byte("base/chain_id")
...
store.Set(baseChainIDKey, []byte(chainID))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, good point
state/kvcache.go
Outdated
e *list.Element // The KVCache.keys element | ||
} | ||
|
||
// NOTE: If store is nil, creates a new MemKVStore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// NewKVCache creates a new KVCache from store.
// If store is nil, it creates a new MemKVStore.
state/kvstore.go
Outdated
type MemKVStore struct { | ||
m map[string][]byte | ||
} | ||
|
||
var _ SimpleDB = NewMemKVStore() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var _ SimpleDB = (*MemKVStore)(nil)
state/kvstore.go
Outdated
keys *list.List | ||
logging bool | ||
logLines []string | ||
func (mkv *MemKVStore) Has(key []byte) (has bool) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a random question: whenever I see a key-value store immediately I imagine concurrent usage, would that apply for this one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are correct, but since the whole blockchain is about serializing transactions, this doesn't apply. You can have two caches over one store (check and deliver), but in the end one will be discarded and there are never concurrent writes while you are reading.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aye aye, thanks for letting me know, TIL.
state/merkle.go
Outdated
merkle.Tree | ||
} | ||
|
||
var _ SimpleDB = &Bonsai{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var _ SimpleDB = (*Bonsai)(nil)
state/merkle.go
Outdated
stopAtCount := func(key []byte, value []byte) (stop bool) { | ||
m := Model{key, value} | ||
res = append(res, m) | ||
// return false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's remove this, please.
state/merkle.go
Outdated
func (b *Bonsai) Commit(sub SimpleDB) error { | ||
bb, ok := sub.(*Bonsai) | ||
if !ok || (b.id != bb.id) { | ||
return errors.New("Not a sub-transaction") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can be lifted out and made a var so
return errNotASubTransaction
app/store.go
Outdated
err = wire.ReadBinaryBytes(eyesStateBytes, &chainState) | ||
if err != nil { | ||
logger.Error("error reading MerkleEyesState", "err", err) | ||
panic(err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We forgot to remove this panic here :)
Thank you for the PR and for addressing my comments @ethanfrey! Just one nit left otherwise LGTM from a code standpoint. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM after removing the last panic mentioned previously.
6d8faec
to
dfdbfa0
Compare
fix: prevent panic in Coins.IsEqual
Export now only exports to file
Lots of improvements:
Middleware to control what parts are committed and what rolledback upon error in DeliverTx (by default, nonce update and fee deduction happens).
Expose more power of IAVLTree, remove, lists and first/last in range
Improve caching mechanism to be adapted to the storage layer