mirror of
https://github.com/tendermint/tendermint.git
synced 2026-09-25 17:34:36 +00:00
Merge from panic branch
This commit is contained in:
@@ -136,9 +136,11 @@ func (pool *BlockPool) PopRequest() {
|
||||
pool.requestsMtx.Lock() // Lock
|
||||
defer pool.requestsMtx.Unlock()
|
||||
|
||||
// SANITY CHECK
|
||||
if r := pool.requests[pool.height]; r == nil || r.block == nil {
|
||||
panic("PopRequest() requires a valid block")
|
||||
}
|
||||
// SANITY CHECK END
|
||||
|
||||
delete(pool.requests, pool.height)
|
||||
pool.height++
|
||||
@@ -151,9 +153,11 @@ func (pool *BlockPool) RedoRequest(height int) {
|
||||
defer pool.requestsMtx.Unlock()
|
||||
|
||||
request := pool.requests[height]
|
||||
// SANITY CHECK
|
||||
if request.block == nil {
|
||||
panic("Expected block to be non-nil")
|
||||
}
|
||||
// SANITY CHECK END
|
||||
// TODO: record this malfeasance
|
||||
// maybe punish peer on switch (an invalid block!)
|
||||
pool.RemovePeer(request.peerId) // Lock on peersMtx.
|
||||
|
||||
@@ -54,10 +54,12 @@ type BlockchainReactor struct {
|
||||
}
|
||||
|
||||
func NewBlockchainReactor(state *sm.State, store *BlockStore, sync bool) *BlockchainReactor {
|
||||
// SANITY CHECK
|
||||
if state.LastBlockHeight != store.Height() &&
|
||||
state.LastBlockHeight != store.Height()-1 { // XXX double check this logic.
|
||||
panic(Fmt("state (%v) and store (%v) height mismatch", state.LastBlockHeight, store.Height()))
|
||||
}
|
||||
// SANITY CHECK END
|
||||
requestsCh := make(chan BlockRequest, defaultChannelCapacity)
|
||||
timeoutsCh := make(chan string, defaultChannelCapacity)
|
||||
pool := NewBlockPool(
|
||||
|
||||
+19
-5
@@ -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