mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-12 04:41:22 +00:00
Merge from panic branch
This commit is contained in:
@ -23,6 +23,8 @@ There are three types of information stored:
|
||||
Currently the precommit signatures are duplicated in the Block parts as
|
||||
well as the Validation. In the future this may change, perhaps by moving
|
||||
the Validation data outside the Block.
|
||||
|
||||
Panics indicate probable corruption in the data
|
||||
*/
|
||||
type BlockStore struct {
|
||||
height int
|
||||
@ -55,10 +57,11 @@ func (bs *BlockStore) LoadBlock(height int) *types.Block {
|
||||
var err error
|
||||
r := bs.GetReader(calcBlockMetaKey(height))
|
||||
if r == nil {
|
||||
panic(Fmt("Block does not exist at height %v", height))
|
||||
return nil
|
||||
}
|
||||
meta := binary.ReadBinary(&types.BlockMeta{}, r, &n, &err).(*types.BlockMeta)
|
||||
if err != nil {
|
||||
// SOMETHING HAS GONE HORRIBLY WRONG
|
||||
panic(Fmt("Error reading block meta: %v", err))
|
||||
}
|
||||
bytez := []byte{}
|
||||
@ -68,6 +71,7 @@ func (bs *BlockStore) LoadBlock(height int) *types.Block {
|
||||
}
|
||||
block := binary.ReadBinary(&types.Block{}, bytes.NewReader(bytez), &n, &err).(*types.Block)
|
||||
if err != nil {
|
||||
// SOMETHING HAS GONE HORRIBLY WRONG
|
||||
panic(Fmt("Error reading block: %v", err))
|
||||
}
|
||||
return block
|
||||
@ -78,10 +82,11 @@ func (bs *BlockStore) LoadBlockPart(height int, index int) *types.Part {
|
||||
var err error
|
||||
r := bs.GetReader(calcBlockPartKey(height, index))
|
||||
if r == nil {
|
||||
panic(Fmt("BlockPart does not exist for height %v index %v", height, index))
|
||||
return nil
|
||||
}
|
||||
part := binary.ReadBinary(&types.Part{}, r, &n, &err).(*types.Part)
|
||||
if err != nil {
|
||||
// SOMETHING HAS GONE HORRIBLY WRONG
|
||||
panic(Fmt("Error reading block part: %v", err))
|
||||
}
|
||||
return part
|
||||
@ -92,10 +97,11 @@ func (bs *BlockStore) LoadBlockMeta(height int) *types.BlockMeta {
|
||||
var err error
|
||||
r := bs.GetReader(calcBlockMetaKey(height))
|
||||
if r == nil {
|
||||
panic(Fmt("BlockMeta does not exist for height %v", height))
|
||||
return nil
|
||||
}
|
||||
meta := binary.ReadBinary(&types.BlockMeta{}, r, &n, &err).(*types.BlockMeta)
|
||||
if err != nil {
|
||||
// SOMETHING HAS GONE HORRIBLY WRONG
|
||||
panic(Fmt("Error reading block meta: %v", err))
|
||||
}
|
||||
return meta
|
||||
@ -108,10 +114,11 @@ func (bs *BlockStore) LoadBlockValidation(height int) *types.Validation {
|
||||
var err error
|
||||
r := bs.GetReader(calcBlockValidationKey(height))
|
||||
if r == nil {
|
||||
panic(Fmt("BlockValidation does not exist for height %v", height))
|
||||
return nil
|
||||
}
|
||||
validation := binary.ReadBinary(&types.Validation{}, r, &n, &err).(*types.Validation)
|
||||
if err != nil {
|
||||
// SOMETHING HAS GONE HORRIBLY WRONG
|
||||
panic(Fmt("Error reading validation: %v", err))
|
||||
}
|
||||
return validation
|
||||
@ -123,10 +130,11 @@ func (bs *BlockStore) LoadSeenValidation(height int) *types.Validation {
|
||||
var err error
|
||||
r := bs.GetReader(calcSeenValidationKey(height))
|
||||
if r == nil {
|
||||
panic(Fmt("SeenValidation does not exist for height %v", height))
|
||||
return nil
|
||||
}
|
||||
validation := binary.ReadBinary(&types.Validation{}, r, &n, &err).(*types.Validation)
|
||||
if err != nil {
|
||||
// SOMETHING HAS GONE HORRIBLY WRONG
|
||||
panic(Fmt("Error reading validation: %v", err))
|
||||
}
|
||||
return validation
|
||||
@ -140,9 +148,11 @@ func (bs *BlockStore) LoadSeenValidation(height int) *types.Validation {
|
||||
func (bs *BlockStore) SaveBlock(block *types.Block, blockParts *types.PartSet, seenValidation *types.Validation) {
|
||||
height := block.Height
|
||||
if height != bs.height+1 {
|
||||
// SANITY CHECK
|
||||
panic(Fmt("BlockStore can only save contiguous blocks. Wanted %v, got %v", bs.height+1, height))
|
||||
}
|
||||
if !blockParts.IsComplete() {
|
||||
// SANITY CHECK
|
||||
panic(Fmt("BlockStore can only save complete block part sets"))
|
||||
}
|
||||
|
||||
@ -172,9 +182,11 @@ func (bs *BlockStore) SaveBlock(block *types.Block, blockParts *types.PartSet, s
|
||||
}
|
||||
|
||||
func (bs *BlockStore) saveBlockPart(height int, index int, part *types.Part) {
|
||||
// SANITY CHECK
|
||||
if height != bs.height+1 {
|
||||
panic(Fmt("BlockStore can only save contiguous blocks. Wanted %v, got %v", bs.height+1, height))
|
||||
}
|
||||
// SANITY CHECK END
|
||||
partBytes := binary.BinaryBytes(part)
|
||||
bs.db.Set(calcBlockPartKey(height, index), partBytes)
|
||||
}
|
||||
@ -208,6 +220,7 @@ type BlockStoreStateJSON struct {
|
||||
func (bsj BlockStoreStateJSON) Save(db dbm.DB) {
|
||||
bytes, err := json.Marshal(bsj)
|
||||
if err != nil {
|
||||
// SANITY CHECK
|
||||
panic(Fmt("Could not marshal state bytes: %v", err))
|
||||
}
|
||||
db.Set(blockStoreKey, bytes)
|
||||
@ -223,6 +236,7 @@ func LoadBlockStoreStateJSON(db dbm.DB) BlockStoreStateJSON {
|
||||
bsj := BlockStoreStateJSON{}
|
||||
err := json.Unmarshal(bytes, &bsj)
|
||||
if err != nil {
|
||||
// SOMETHING HAS GONE HORRIBLY WRONG
|
||||
panic(Fmt("Could not unmarshal bytes: %X", bytes))
|
||||
}
|
||||
return bsj
|
||||
|
Reference in New Issue
Block a user