Clean up state.State as we only support persistence

This commit is contained in:
Ethan Frey 2017-10-17 12:13:37 +02:00
parent 4855b3c9d9
commit fbe88ee275
1 changed files with 10 additions and 24 deletions

View File

@ -5,19 +5,17 @@ import "github.com/tendermint/iavl"
// State represents the app states, separating the commited state (for queries) // State represents the app states, separating the commited state (for queries)
// from the working state (for CheckTx and AppendTx) // from the working state (for CheckTx and AppendTx)
type State struct { type State struct {
committed *Bonsai committed *Bonsai
deliverTx SimpleDB deliverTx SimpleDB
checkTx SimpleDB checkTx SimpleDB
persistent bool
} }
func NewState(tree *iavl.VersionedTree) *State { func NewState(tree *iavl.VersionedTree) *State {
base := NewBonsai(tree) base := NewBonsai(tree)
return &State{ return &State{
committed: base, committed: base,
deliverTx: base.Checkpoint(), deliverTx: base.Checkpoint(),
checkTx: base.Checkpoint(), checkTx: base.Checkpoint(),
persistent: true,
} }
} }
@ -45,14 +43,6 @@ func (s State) LatestHash() []byte {
return s.committed.Tree.Hash() return s.committed.Tree.Hash()
} }
// BatchSet is used for some weird magic in storing the new height
func (s *State) BatchSet(key, value []byte) {
if s.persistent {
// This is in the batch with the Save, but not in the tree
s.committed.Tree.BatchSet(key, value)
}
}
// Commit save persistent nodes to the database and re-copies the trees // Commit save persistent nodes to the database and re-copies the trees
func (s *State) Commit(version uint64) ([]byte, error) { func (s *State) Commit(version uint64) ([]byte, error) {
// commit (if we didn't do hash earlier) // commit (if we didn't do hash earlier)
@ -62,15 +52,11 @@ func (s *State) Commit(version uint64) ([]byte, error) {
} }
var hash []byte var hash []byte
if s.persistent { if s.committed.Tree.Size() > 0 || s.committed.Tree.LatestVersion() > 0 {
if s.committed.Tree.Size() > 0 || s.committed.Tree.LatestVersion() > 0 { hash, err = s.committed.Tree.SaveVersion(version)
hash, err = s.committed.Tree.SaveVersion(version) if err != nil {
if err != nil { return nil, err
return nil, err
}
} }
} else {
hash = s.committed.Tree.Hash()
} }
s.deliverTx = s.committed.Checkpoint() s.deliverTx = s.committed.Checkpoint()