block_height is int32

This commit is contained in:
Ethan Buchman 2016-11-06 02:02:08 +00:00
parent ddb2b01631
commit df299d03c4
2 changed files with 33 additions and 33 deletions

View File

@ -10,38 +10,6 @@ import (
"github.com/tendermint/tmsp/types"
)
//-----------------------------------------
// persist the last block info
var lastBlockKey = []byte("lastblock")
// Get the last block from the db
func LoadLastBlock(db dbm.DB) (lastBlock types.LastBlockInfo) {
buf := db.Get(lastBlockKey)
if len(buf) != 0 {
r, n, err := bytes.NewReader(buf), new(int), new(error)
wire.ReadBinaryPtr(&lastBlock, r, 0, n, err)
if *err != nil {
// DATA HAS BEEN CORRUPTED OR THE SPEC HAS CHANGED
Exit(Fmt("Data has been corrupted or its spec has changed: %v\n", *err))
}
// TODO: ensure that buf is completely read.
}
return lastBlock
}
func SaveLastBlock(db dbm.DB, lastBlock types.LastBlockInfo) {
log.Notice("Saving block", "height", lastBlock.BlockHeight, "hash", lastBlock.BlockHash, "root", lastBlock.AppHash)
buf, n, err := new(bytes.Buffer), new(int), new(error)
wire.WriteBinary(lastBlock, buf, n, err)
if *err != nil {
// TODO
PanicCrisis(*err)
}
db.Set(lastBlockKey, buf.Bytes())
}
//-----------------------------------------
type PersistentDummyApplication struct {
@ -120,3 +88,35 @@ func (app *PersistentDummyApplication) BeginBlock(hash []byte, header *types.Hea
func (app *PersistentDummyApplication) EndBlock(height uint64) (diffs []*types.Validator) {
return nil
}
//-----------------------------------------
// persist the last block info
var lastBlockKey = []byte("lastblock")
// Get the last block from the db
func LoadLastBlock(db dbm.DB) (lastBlock types.LastBlockInfo) {
buf := db.Get(lastBlockKey)
if len(buf) != 0 {
r, n, err := bytes.NewReader(buf), new(int), new(error)
wire.ReadBinaryPtr(&lastBlock, r, 0, n, err)
if *err != nil {
// DATA HAS BEEN CORRUPTED OR THE SPEC HAS CHANGED
Exit(Fmt("Data has been corrupted or its spec has changed: %v\n", *err))
}
// TODO: ensure that buf is completely read.
}
return lastBlock
}
func SaveLastBlock(db dbm.DB, lastBlock types.LastBlockInfo) {
log.Notice("Saving block", "height", lastBlock.BlockHeight, "hash", lastBlock.BlockHash, "root", lastBlock.AppHash)
buf, n, err := new(bytes.Buffer), new(int), new(error)
wire.WriteBinary(lastBlock, buf, n, err)
if *err != nil {
// TODO
PanicCrisis(*err)
}
db.Set(lastBlockKey, buf.Bytes())
}

View File

@ -219,7 +219,7 @@ message TMSPInfo {
}
message LastBlockInfo {
uint64 block_height = 1;
int32 block_height = 1;
bytes block_hash = 2;
bytes app_hash = 3;
}