Cleanup some todos
This commit is contained in:
parent
cdaee322bc
commit
0b9be1069f
|
@ -112,7 +112,7 @@ func (s *Store) Info() abci.ResponseInfo {
|
||||||
"height", s.height,
|
"height", s.height,
|
||||||
"hash", fmt.Sprintf("%X", s.hash))
|
"hash", fmt.Sprintf("%X", s.hash))
|
||||||
return abci.ResponseInfo{
|
return abci.ResponseInfo{
|
||||||
Data: cmn.Fmt("size:%v", s.State.Committed().Size()),
|
Data: cmn.Fmt("size:%v", s.State.Size()),
|
||||||
LastBlockHeight: s.height - 1,
|
LastBlockHeight: s.height - 1,
|
||||||
LastBlockAppHash: s.hash,
|
LastBlockAppHash: s.hash,
|
||||||
}
|
}
|
||||||
|
@ -144,7 +144,7 @@ func (s *Store) Commit() abci.Result {
|
||||||
return abci.NewError(abci.CodeType_InternalError, "AppHash is incorrect")
|
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(nil, "Empty hash for empty tree")
|
||||||
}
|
}
|
||||||
return abci.NewResultOK(s.hash, "")
|
return abci.NewResultOK(s.hash, "")
|
||||||
|
|
|
@ -12,7 +12,7 @@ type nonce int64
|
||||||
// Bonsai is a deformed tree forced to fit in a small pot
|
// Bonsai is a deformed tree forced to fit in a small pot
|
||||||
type Bonsai struct {
|
type Bonsai struct {
|
||||||
id nonce
|
id nonce
|
||||||
merkle.Tree
|
Tree merkle.Tree
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ SimpleDB = &Bonsai{}
|
var _ SimpleDB = &Bonsai{}
|
||||||
|
@ -31,6 +31,11 @@ func (b *Bonsai) Get(key []byte) []byte {
|
||||||
return value
|
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
|
// Set matches the signature of KVStore
|
||||||
func (b *Bonsai) Set(key, value []byte) {
|
func (b *Bonsai) Set(key, value []byte) {
|
||||||
b.Tree.Set(key, value)
|
b.Tree.Set(key, value)
|
||||||
|
@ -41,6 +46,10 @@ func (b *Bonsai) Remove(key []byte) (value []byte) {
|
||||||
return
|
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 {
|
func (b *Bonsai) List(start, end []byte, limit int) []Model {
|
||||||
res := []Model{}
|
res := []Model{}
|
||||||
stopAtCount := func(key []byte, value []byte) (stop bool) {
|
stopAtCount := func(key []byte, value []byte) (stop bool) {
|
||||||
|
|
|
@ -117,7 +117,12 @@ func (c *MemKVCache) Commit(sub SimpleDB) error {
|
||||||
if !ok {
|
if !ok {
|
||||||
return ErrNotASubTransaction()
|
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
|
// apply the cached data to us
|
||||||
cache.applyCache()
|
cache.applyCache()
|
||||||
|
|
|
@ -149,7 +149,12 @@ func (m *MemKVStore) Commit(sub SimpleDB) error {
|
||||||
if !ok {
|
if !ok {
|
||||||
return ErrNotASubTransaction()
|
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
|
// apply the cached data to us
|
||||||
cache.applyCache()
|
cache.applyCache()
|
||||||
|
|
|
@ -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 {
|
func (s State) Committed() *Bonsai {
|
||||||
return s.committed
|
return s.committed
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue