Make sure height in store increments every block, even if empty

This commit is contained in:
Ethan Frey 2017-10-10 14:53:58 +02:00
parent 9092b4d7f1
commit 5238448a46
3 changed files with 12 additions and 24 deletions

View File

@ -165,7 +165,6 @@ func (app *Basecoin) InitChain(req abci.RequestInitChain) {
// BeginBlock - ABCI
func (app *Basecoin) BeginBlock(req abci.RequestBeginBlock) {
fmt.Println("BeginBlock")
app.height++
// for _, plugin := range app.plugins.GetList() {
// plugin.BeginBlock(app.state, hash, header)

View File

@ -19,6 +19,7 @@ import (
// Store contains the merkle tree, and all info to handle abci requests
type Store struct {
state.State
height uint64
logger log.Logger
}
@ -81,14 +82,10 @@ func NewStore(dbName string, cacheSize int, logger log.Logger) (*Store, error) {
State: state.NewState(tree),
logger: logger,
}
res.height = res.State.LatestHeight()
return res, nil
}
// Height gets the last height stored in the database
func (s *Store) Height() uint64 {
return s.State.LatestHeight()
}
// Hash gets the last hash stored in the database
func (s *Store) Hash() []byte {
return s.State.LatestHash()
@ -98,32 +95,31 @@ func (s *Store) Hash() []byte {
// The height is the block that holds the transactions, not the apphash itself.
func (s *Store) Info() abci.ResponseInfo {
s.logger.Info("Info synced",
"height", s.Height(),
"height", s.height,
"hash", fmt.Sprintf("%X", s.Hash()))
return abci.ResponseInfo{
Data: cmn.Fmt("size:%v", s.State.Size()),
LastBlockHeight: s.Height() - 1,
LastBlockHeight: s.height - 1,
LastBlockAppHash: s.Hash(),
}
}
// Commit implements abci.Application
func (s *Store) Commit() abci.Result {
height := s.Height() + 1
s.height++
hash, err := s.State.Commit(height)
hash, err := s.State.Commit(s.height)
if err != nil {
return abci.NewError(abci.CodeType_InternalError, err.Error())
}
s.logger.Debug("Commit synced",
"height", height,
"height", s.height,
"hash", fmt.Sprintf("%X", hash),
)
if s.State.Size() == 0 {
return abci.NewResultOK(nil, "Empty hash for empty tree")
}
fmt.Printf("ABCI Commit: %d / %X\n", height, hash)
return abci.NewResultOK(hash, "")
}
@ -134,10 +130,10 @@ func (s *Store) Query(reqQuery abci.RequestQuery) (resQuery abci.ResponseQuery)
height := reqQuery.Height
if height == 0 {
if tree.Tree.VersionExists(s.Height() - 1) {
height = s.Height() - 1
if tree.Tree.VersionExists(s.height - 1) {
height = s.height - 1
} else {
height = s.Height()
height = s.height
}
}
resQuery.Height = height

View File

@ -1,8 +1,6 @@
package client
import (
"fmt"
"github.com/pkg/errors"
"github.com/tendermint/go-wire/data"
@ -41,9 +39,9 @@ func GetWithProof(key []byte, node client.Client, cert certifiers.Certifier) (
return
}
// AppHash for height H is in header H+1
var check lc.Checkpoint
// check, err = GetCertifiedCheckpoint(int(resp.Height), node, cert)
check, err = GetCertifiedCheckpoint(int(resp.Height+9), node, cert)
check, err = GetCertifiedCheckpoint(int(resp.Height+1), node, cert)
if err != nil {
return
}
@ -73,11 +71,6 @@ func GetWithProof(key []byte, node client.Client, cert certifiers.Certifier) (
err = errors.Wrap(err, "Error reading proof")
return
}
fmt.Printf("apphash: %x\n", check.Header.AppHash)
fmt.Printf("proof hash: %x\n", aproof.Root())
fmt.Printf("response height: %d\n", resp.Height)
// Validate the proof against the certified header to ensure data integrity.
err = aproof.Verify(resp.Key, nil, check.Header.AppHash)
if err != nil {