|
|
@ -9,7 +9,7 @@ import ( |
|
|
|
|
|
|
|
"github.com/tendermint/go-wire" |
|
|
|
"github.com/tendermint/tendermint/types" |
|
|
|
. "github.com/tendermint/tmlibs/common" |
|
|
|
cmn "github.com/tendermint/tmlibs/common" |
|
|
|
dbm "github.com/tendermint/tmlibs/db" |
|
|
|
) |
|
|
|
|
|
|
@ -67,7 +67,7 @@ func (bs *BlockStore) LoadBlock(height int) *types.Block { |
|
|
|
} |
|
|
|
blockMeta := wire.ReadBinary(&types.BlockMeta{}, r, 0, &n, &err).(*types.BlockMeta) |
|
|
|
if err != nil { |
|
|
|
PanicCrisis(Fmt("Error reading block meta: %v", err)) |
|
|
|
cmn.PanicCrisis(cmn.Fmt("Error reading block meta: %v", err)) |
|
|
|
} |
|
|
|
bytez := []byte{} |
|
|
|
for i := 0; i < blockMeta.BlockID.PartsHeader.Total; i++ { |
|
|
@ -76,7 +76,7 @@ func (bs *BlockStore) LoadBlock(height int) *types.Block { |
|
|
|
} |
|
|
|
block := wire.ReadBinary(&types.Block{}, bytes.NewReader(bytez), 0, &n, &err).(*types.Block) |
|
|
|
if err != nil { |
|
|
|
PanicCrisis(Fmt("Error reading block: %v", err)) |
|
|
|
cmn.PanicCrisis(cmn.Fmt("Error reading block: %v", err)) |
|
|
|
} |
|
|
|
return block |
|
|
|
} |
|
|
@ -90,7 +90,7 @@ func (bs *BlockStore) LoadBlockPart(height int, index int) *types.Part { |
|
|
|
} |
|
|
|
part := wire.ReadBinary(&types.Part{}, r, 0, &n, &err).(*types.Part) |
|
|
|
if err != nil { |
|
|
|
PanicCrisis(Fmt("Error reading block part: %v", err)) |
|
|
|
cmn.PanicCrisis(cmn.Fmt("Error reading block part: %v", err)) |
|
|
|
} |
|
|
|
return part |
|
|
|
} |
|
|
@ -104,7 +104,7 @@ func (bs *BlockStore) LoadBlockMeta(height int) *types.BlockMeta { |
|
|
|
} |
|
|
|
blockMeta := wire.ReadBinary(&types.BlockMeta{}, r, 0, &n, &err).(*types.BlockMeta) |
|
|
|
if err != nil { |
|
|
|
PanicCrisis(Fmt("Error reading block meta: %v", err)) |
|
|
|
cmn.PanicCrisis(cmn.Fmt("Error reading block meta: %v", err)) |
|
|
|
} |
|
|
|
return blockMeta |
|
|
|
} |
|
|
@ -120,7 +120,7 @@ func (bs *BlockStore) LoadBlockCommit(height int) *types.Commit { |
|
|
|
} |
|
|
|
commit := wire.ReadBinary(&types.Commit{}, r, 0, &n, &err).(*types.Commit) |
|
|
|
if err != nil { |
|
|
|
PanicCrisis(Fmt("Error reading commit: %v", err)) |
|
|
|
cmn.PanicCrisis(cmn.Fmt("Error reading commit: %v", err)) |
|
|
|
} |
|
|
|
return commit |
|
|
|
} |
|
|
@ -135,7 +135,7 @@ func (bs *BlockStore) LoadSeenCommit(height int) *types.Commit { |
|
|
|
} |
|
|
|
commit := wire.ReadBinary(&types.Commit{}, r, 0, &n, &err).(*types.Commit) |
|
|
|
if err != nil { |
|
|
|
PanicCrisis(Fmt("Error reading commit: %v", err)) |
|
|
|
cmn.PanicCrisis(cmn.Fmt("Error reading commit: %v", err)) |
|
|
|
} |
|
|
|
return commit |
|
|
|
} |
|
|
@ -148,10 +148,10 @@ func (bs *BlockStore) LoadSeenCommit(height int) *types.Commit { |
|
|
|
func (bs *BlockStore) SaveBlock(block *types.Block, blockParts *types.PartSet, seenCommit *types.Commit) { |
|
|
|
height := block.Height |
|
|
|
if height != bs.Height()+1 { |
|
|
|
PanicSanity(Fmt("BlockStore can only save contiguous blocks. Wanted %v, got %v", bs.Height()+1, height)) |
|
|
|
cmn.PanicSanity(cmn.Fmt("BlockStore can only save contiguous blocks. Wanted %v, got %v", bs.Height()+1, height)) |
|
|
|
} |
|
|
|
if !blockParts.IsComplete() { |
|
|
|
PanicSanity(Fmt("BlockStore can only save complete block part sets")) |
|
|
|
cmn.PanicSanity(cmn.Fmt("BlockStore can only save complete block part sets")) |
|
|
|
} |
|
|
|
|
|
|
|
// Save block meta
|
|
|
@ -187,7 +187,7 @@ func (bs *BlockStore) SaveBlock(block *types.Block, blockParts *types.PartSet, s |
|
|
|
|
|
|
|
func (bs *BlockStore) saveBlockPart(height int, index int, part *types.Part) { |
|
|
|
if height != bs.Height()+1 { |
|
|
|
PanicSanity(Fmt("BlockStore can only save contiguous blocks. Wanted %v, got %v", bs.Height()+1, height)) |
|
|
|
cmn.PanicSanity(cmn.Fmt("BlockStore can only save contiguous blocks. Wanted %v, got %v", bs.Height()+1, height)) |
|
|
|
} |
|
|
|
partBytes := wire.BinaryBytes(part) |
|
|
|
bs.db.Set(calcBlockPartKey(height, index), partBytes) |
|
|
@ -222,7 +222,7 @@ type BlockStoreStateJSON struct { |
|
|
|
func (bsj BlockStoreStateJSON) Save(db dbm.DB) { |
|
|
|
bytes, err := json.Marshal(bsj) |
|
|
|
if err != nil { |
|
|
|
PanicSanity(Fmt("Could not marshal state bytes: %v", err)) |
|
|
|
cmn.PanicSanity(cmn.Fmt("Could not marshal state bytes: %v", err)) |
|
|
|
} |
|
|
|
db.SetSync(blockStoreKey, bytes) |
|
|
|
} |
|
|
@ -237,7 +237,7 @@ func LoadBlockStoreStateJSON(db dbm.DB) BlockStoreStateJSON { |
|
|
|
bsj := BlockStoreStateJSON{} |
|
|
|
err := json.Unmarshal(bytes, &bsj) |
|
|
|
if err != nil { |
|
|
|
PanicCrisis(Fmt("Could not unmarshal bytes: %X", bytes)) |
|
|
|
cmn.PanicCrisis(cmn.Fmt("Could not unmarshal bytes: %X", bytes)) |
|
|
|
} |
|
|
|
return bsj |
|
|
|
} |