Cleanup some todos

This commit is contained in:
Ethan Frey 2017-08-03 16:58:37 +02:00
parent cdaee322bc
commit 0b9be1069f
5 changed files with 29 additions and 6 deletions

View File

@ -112,7 +112,7 @@ func (s *Store) Info() abci.ResponseInfo {
"height", s.height,
"hash", fmt.Sprintf("%X", s.hash))
return abci.ResponseInfo{
Data: cmn.Fmt("size:%v", s.State.Committed().Size()),
Data: cmn.Fmt("size:%v", s.State.Size()),
LastBlockHeight: s.height - 1,
LastBlockAppHash: s.hash,
}
@ -144,7 +144,7 @@ func (s *Store) Commit() abci.Result {
return abci.NewError(abci.CodeType_InternalError, "AppHash is incorrect")
}
if s.State.Committed().Size() == 0 {
if s.State.Size() == 0 {
return abci.NewResultOK(nil, "Empty hash for empty tree")
}
return abci.NewResultOK(s.hash, "")

View File

@ -11,8 +11,8 @@ type nonce int64
// Bonsai is a deformed tree forced to fit in a small pot
type Bonsai struct {
id nonce
merkle.Tree
id nonce
Tree merkle.Tree
}
var _ SimpleDB = &Bonsai{}
@ -31,6 +31,11 @@ func (b *Bonsai) Get(key []byte) []byte {
return value
}
// Get matches the signature of KVStore
func (b *Bonsai) Has(key []byte) bool {
return b.Tree.Has(key)
}
// Set matches the signature of KVStore
func (b *Bonsai) Set(key, value []byte) {
b.Tree.Set(key, value)
@ -41,6 +46,10 @@ func (b *Bonsai) Remove(key []byte) (value []byte) {
return
}
func (b *Bonsai) Proof(key []byte) (value []byte, proof []byte, exists bool) {
return b.Tree.Proof(key)
}
func (b *Bonsai) List(start, end []byte, limit int) []Model {
res := []Model{}
stopAtCount := func(key []byte, value []byte) (stop bool) {

View File

@ -117,7 +117,12 @@ func (c *MemKVCache) Commit(sub SimpleDB) error {
if !ok {
return ErrNotASubTransaction()
}
// TODO: see if it points to us
// see if it points to us
ref, ok := cache.store.(*MemKVCache)
if !ok || ref != c {
return ErrNotASubTransaction()
}
// apply the cached data to us
cache.applyCache()

View File

@ -149,7 +149,12 @@ func (m *MemKVStore) Commit(sub SimpleDB) error {
if !ok {
return ErrNotASubTransaction()
}
// TODO: see if it points to us
// see if it points to us
ref, ok := cache.store.(*MemKVStore)
if !ok || ref != m {
return ErrNotASubTransaction()
}
// apply the cached data to us
cache.applyCache()

View File

@ -24,6 +24,10 @@ func NewState(tree merkle.Tree, persistent bool) State {
}
}
func (s State) Size() int {
return s.committed.Tree.Size()
}
func (s State) Committed() *Bonsai {
return s.committed
}