Make sure height in store increments every block, even if empty
This commit is contained in:
parent
9092b4d7f1
commit
5238448a46
|
@ -165,7 +165,6 @@ func (app *Basecoin) InitChain(req abci.RequestInitChain) {
|
||||||
|
|
||||||
// BeginBlock - ABCI
|
// BeginBlock - ABCI
|
||||||
func (app *Basecoin) BeginBlock(req abci.RequestBeginBlock) {
|
func (app *Basecoin) BeginBlock(req abci.RequestBeginBlock) {
|
||||||
fmt.Println("BeginBlock")
|
|
||||||
app.height++
|
app.height++
|
||||||
// for _, plugin := range app.plugins.GetList() {
|
// for _, plugin := range app.plugins.GetList() {
|
||||||
// plugin.BeginBlock(app.state, hash, header)
|
// plugin.BeginBlock(app.state, hash, header)
|
||||||
|
|
24
app/store.go
24
app/store.go
|
@ -19,6 +19,7 @@ import (
|
||||||
// Store contains the merkle tree, and all info to handle abci requests
|
// Store contains the merkle tree, and all info to handle abci requests
|
||||||
type Store struct {
|
type Store struct {
|
||||||
state.State
|
state.State
|
||||||
|
height uint64
|
||||||
logger log.Logger
|
logger log.Logger
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,14 +82,10 @@ func NewStore(dbName string, cacheSize int, logger log.Logger) (*Store, error) {
|
||||||
State: state.NewState(tree),
|
State: state.NewState(tree),
|
||||||
logger: logger,
|
logger: logger,
|
||||||
}
|
}
|
||||||
|
res.height = res.State.LatestHeight()
|
||||||
return res, nil
|
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
|
// Hash gets the last hash stored in the database
|
||||||
func (s *Store) Hash() []byte {
|
func (s *Store) Hash() []byte {
|
||||||
return s.State.LatestHash()
|
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.
|
// The height is the block that holds the transactions, not the apphash itself.
|
||||||
func (s *Store) Info() abci.ResponseInfo {
|
func (s *Store) Info() abci.ResponseInfo {
|
||||||
s.logger.Info("Info synced",
|
s.logger.Info("Info synced",
|
||||||
"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.Size()),
|
Data: cmn.Fmt("size:%v", s.State.Size()),
|
||||||
LastBlockHeight: s.Height() - 1,
|
LastBlockHeight: s.height - 1,
|
||||||
LastBlockAppHash: s.Hash(),
|
LastBlockAppHash: s.Hash(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Commit implements abci.Application
|
// Commit implements abci.Application
|
||||||
func (s *Store) Commit() abci.Result {
|
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 {
|
if err != nil {
|
||||||
return abci.NewError(abci.CodeType_InternalError, err.Error())
|
return abci.NewError(abci.CodeType_InternalError, err.Error())
|
||||||
}
|
}
|
||||||
s.logger.Debug("Commit synced",
|
s.logger.Debug("Commit synced",
|
||||||
"height", height,
|
"height", s.height,
|
||||||
"hash", fmt.Sprintf("%X", hash),
|
"hash", fmt.Sprintf("%X", hash),
|
||||||
)
|
)
|
||||||
|
|
||||||
if s.State.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")
|
||||||
}
|
}
|
||||||
fmt.Printf("ABCI Commit: %d / %X\n", height, hash)
|
|
||||||
return abci.NewResultOK(hash, "")
|
return abci.NewResultOK(hash, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,10 +130,10 @@ func (s *Store) Query(reqQuery abci.RequestQuery) (resQuery abci.ResponseQuery)
|
||||||
|
|
||||||
height := reqQuery.Height
|
height := reqQuery.Height
|
||||||
if height == 0 {
|
if height == 0 {
|
||||||
if tree.Tree.VersionExists(s.Height() - 1) {
|
if tree.Tree.VersionExists(s.height - 1) {
|
||||||
height = s.Height() - 1
|
height = s.height - 1
|
||||||
} else {
|
} else {
|
||||||
height = s.Height()
|
height = s.height
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
resQuery.Height = height
|
resQuery.Height = height
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
package client
|
package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
"github.com/tendermint/go-wire/data"
|
"github.com/tendermint/go-wire/data"
|
||||||
|
@ -41,9 +39,9 @@ func GetWithProof(key []byte, node client.Client, cert certifiers.Certifier) (
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AppHash for height H is in header H+1
|
||||||
var check lc.Checkpoint
|
var check lc.Checkpoint
|
||||||
// check, err = GetCertifiedCheckpoint(int(resp.Height), node, cert)
|
check, err = GetCertifiedCheckpoint(int(resp.Height+1), node, cert)
|
||||||
check, err = GetCertifiedCheckpoint(int(resp.Height+9), node, cert)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -73,11 +71,6 @@ func GetWithProof(key []byte, node client.Client, cert certifiers.Certifier) (
|
||||||
err = errors.Wrap(err, "Error reading proof")
|
err = errors.Wrap(err, "Error reading proof")
|
||||||
return
|
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.
|
// Validate the proof against the certified header to ensure data integrity.
|
||||||
err = aproof.Verify(resp.Key, nil, check.Header.AppHash)
|
err = aproof.Verify(resp.Key, nil, check.Header.AppHash)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue