mirror of
https://github.com/tendermint/tendermint.git
synced 2026-02-08 21:10:10 +00:00
simplify state
This commit is contained in:
@@ -199,7 +199,7 @@ func (app *MerkleEyesApp) Info(req abci.RequestInfo) abci.ResponseInfo {
|
||||
Version: version.ABCIVersion,
|
||||
AppVersion: 1,
|
||||
LastBlockHeight: app.height,
|
||||
LastBlockAppHash: app.state.Deliver().Hash(),
|
||||
LastBlockAppHash: app.state.Committed().Hash(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -210,7 +210,7 @@ func (app *MerkleEyesApp) InitChain(req abci.RequestInitChain) abci.ResponseInit
|
||||
}
|
||||
|
||||
return abci.ResponseInitChain{
|
||||
AppHash: app.state.Deliver().Hash(),
|
||||
AppHash: app.state.Committed().Hash(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -221,7 +221,7 @@ func (app *MerkleEyesApp) CheckTx(_ abci.RequestCheckTx) abci.ResponseCheckTx {
|
||||
|
||||
// DeliverTx implements ABCI.
|
||||
func (app *MerkleEyesApp) DeliverTx(req abci.RequestDeliverTx) abci.ResponseDeliverTx {
|
||||
tree := app.state.Deliver()
|
||||
tree := app.state.Working()
|
||||
r := app.doTx(tree, req.Tx)
|
||||
if r.IsErr() {
|
||||
fmt.Println("DeliverTx Err", r)
|
||||
@@ -273,8 +273,7 @@ func (app *MerkleEyesApp) Query(req abci.RequestQuery) (res abci.ResponseQuery)
|
||||
if len(req.Data) == 0 {
|
||||
return
|
||||
}
|
||||
// tree := app.state.Committed()
|
||||
tree := app.state.Deliver()
|
||||
tree := app.state.Committed()
|
||||
|
||||
if req.Height != 0 {
|
||||
// TODO: support older commits
|
||||
|
||||
@@ -5,47 +5,43 @@ import (
|
||||
)
|
||||
|
||||
// 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 DeliverTx).
|
||||
type State struct {
|
||||
deliverTx *iavl.MutableTree
|
||||
checkTx *iavl.ImmutableTree
|
||||
persistent bool
|
||||
working *iavl.MutableTree
|
||||
committed *iavl.ImmutableTree
|
||||
}
|
||||
|
||||
func NewState(tree *iavl.MutableTree, version int64, persistent bool) State {
|
||||
iTree, err := tree.GetImmutable(0)
|
||||
func NewState(tree *iavl.MutableTree, lastVersion int64) State {
|
||||
iTree, err := tree.GetImmutable(lastVersion)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return State{
|
||||
deliverTx: tree,
|
||||
checkTx: iTree,
|
||||
persistent: persistent,
|
||||
working: tree,
|
||||
committed: iTree,
|
||||
}
|
||||
}
|
||||
|
||||
func (s State) Deliver() *iavl.MutableTree {
|
||||
return s.deliverTx
|
||||
func (s State) Working() *iavl.MutableTree {
|
||||
return s.working
|
||||
}
|
||||
|
||||
func (s State) Check() *iavl.ImmutableTree {
|
||||
return s.checkTx
|
||||
func (s State) Committed() *iavl.ImmutableTree {
|
||||
return s.committed
|
||||
}
|
||||
|
||||
// Commit stores the current Deliver() state as committed
|
||||
// starts new Append/Check state, and
|
||||
// returns the hash for the commit
|
||||
func (s *State) Commit() []byte {
|
||||
hash, version, err := s.deliverTx.SaveVersion()
|
||||
hash, version, err := s.working.SaveVersion()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
iTree, err := s.deliverTx.GetImmutable(version)
|
||||
iTree, err := s.working.GetImmutable(version)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
s.checkTx = iTree
|
||||
s.committed = iTree
|
||||
|
||||
return hash
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user