panic wrapper functions

This commit is contained in:
Ethan Buchman
2015-07-21 10:46:05 -04:00
parent 5983088a32
commit 8e50bf15de
45 changed files with 229 additions and 275 deletions
+2 -6
View File
@@ -126,11 +126,9 @@ 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")
PanicSanity("PopRequest() requires a valid block")
}
// SANITY CHECK END
delete(pool.requests, pool.height)
pool.height++
@@ -143,11 +141,9 @@ 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")
PanicSanity("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.
+2 -4
View File
@@ -53,12 +53,10 @@ 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()))
PanicSanity(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(
@@ -231,7 +229,7 @@ FOR_LOOP:
err := sm.ExecBlock(bcR.state, first, firstPartsHeader)
if err != nil {
// TODO This is bad, are we zombie?
panic(Fmt("Failed to process committed block: %v", err))
PanicQ(Fmt("Failed to process committed block: %v", err))
}
bcR.store.SaveBlock(first, firstParts, second.LastValidation)
bcR.state.Save()
+11 -23
View File
@@ -61,8 +61,7 @@ func (bs *BlockStore) LoadBlock(height int) *types.Block {
}
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))
PanicCrisis(Fmt("Error reading block meta: %v", err))
}
bytez := []byte{}
for i := 0; i < meta.PartsHeader.Total; i++ {
@@ -71,8 +70,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))
PanicCrisis(Fmt("Error reading block: %v", err))
}
return block
}
@@ -86,8 +84,7 @@ func (bs *BlockStore) LoadBlockPart(height int, index int) *types.Part {
}
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))
PanicCrisis(Fmt("Error reading block part: %v", err))
}
return part
}
@@ -101,8 +98,7 @@ func (bs *BlockStore) LoadBlockMeta(height int) *types.BlockMeta {
}
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))
PanicCrisis(Fmt("Error reading block meta: %v", err))
}
return meta
}
@@ -118,8 +114,7 @@ func (bs *BlockStore) LoadBlockValidation(height int) *types.Validation {
}
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))
PanicCrisis(Fmt("Error reading validation: %v", err))
}
return validation
}
@@ -134,8 +129,7 @@ func (bs *BlockStore) LoadSeenValidation(height int) *types.Validation {
}
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))
PanicCrisis(Fmt("Error reading validation: %v", err))
}
return validation
}
@@ -148,12 +142,10 @@ 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))
PanicSanity(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"))
PanicSanity(Fmt("BlockStore can only save complete block part sets"))
}
// Save block meta
@@ -182,11 +174,9 @@ 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))
PanicSanity(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)
}
@@ -220,8 +210,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))
PanicSanity(Fmt("Could not marshal state bytes: %v", err))
}
db.Set(blockStoreKey, bytes)
}
@@ -236,8 +225,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))
PanicCrisis(Fmt("Could not unmarshal bytes: %X", bytes))
}
return bsj
}