mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-15 14:21:22 +00:00
BlockMeta uses BlockID
This commit is contained in:
@ -64,12 +64,12 @@ func (bs *BlockStore) LoadBlock(height int) *types.Block {
|
|||||||
if r == nil {
|
if r == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
meta := wire.ReadBinary(&types.BlockMeta{}, r, 0, &n, &err).(*types.BlockMeta)
|
blockMeta := wire.ReadBinary(&types.BlockMeta{}, r, 0, &n, &err).(*types.BlockMeta)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
PanicCrisis(Fmt("Error reading block meta: %v", err))
|
PanicCrisis(Fmt("Error reading block meta: %v", err))
|
||||||
}
|
}
|
||||||
bytez := []byte{}
|
bytez := []byte{}
|
||||||
for i := 0; i < meta.PartsHeader.Total; i++ {
|
for i := 0; i < blockMeta.BlockID.PartsHeader.Total; i++ {
|
||||||
part := bs.LoadBlockPart(height, i)
|
part := bs.LoadBlockPart(height, i)
|
||||||
bytez = append(bytez, part.Bytes...)
|
bytez = append(bytez, part.Bytes...)
|
||||||
}
|
}
|
||||||
@ -101,11 +101,11 @@ func (bs *BlockStore) LoadBlockMeta(height int) *types.BlockMeta {
|
|||||||
if r == nil {
|
if r == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
meta := wire.ReadBinary(&types.BlockMeta{}, r, 0, &n, &err).(*types.BlockMeta)
|
blockMeta := wire.ReadBinary(&types.BlockMeta{}, r, 0, &n, &err).(*types.BlockMeta)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
PanicCrisis(Fmt("Error reading block meta: %v", err))
|
PanicCrisis(Fmt("Error reading block meta: %v", err))
|
||||||
}
|
}
|
||||||
return meta
|
return blockMeta
|
||||||
}
|
}
|
||||||
|
|
||||||
// The +2/3 and other Precommit-votes for block at `height`.
|
// The +2/3 and other Precommit-votes for block at `height`.
|
||||||
@ -154,8 +154,8 @@ func (bs *BlockStore) SaveBlock(block *types.Block, blockParts *types.PartSet, s
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Save block meta
|
// Save block meta
|
||||||
meta := types.NewBlockMeta(block, blockParts)
|
blockMeta := types.NewBlockMeta(block, blockParts)
|
||||||
metaBytes := wire.BinaryBytes(meta)
|
metaBytes := wire.BinaryBytes(blockMeta)
|
||||||
bs.db.Set(calcBlockMetaKey(height), metaBytes)
|
bs.db.Set(calcBlockMetaKey(height), metaBytes)
|
||||||
|
|
||||||
// Save block parts
|
// Save block parts
|
||||||
|
@ -415,9 +415,9 @@ OUTER_LOOP:
|
|||||||
log.Warn("Failed to load block meta", "peer height", prs.Height, "our height", rs.Height, "blockstore height", conR.conS.blockStore.Height(), "pv", conR.conS.privValidator)
|
log.Warn("Failed to load block meta", "peer height", prs.Height, "our height", rs.Height, "blockstore height", conR.conS.blockStore.Height(), "pv", conR.conS.privValidator)
|
||||||
time.Sleep(peerGossipSleepDuration)
|
time.Sleep(peerGossipSleepDuration)
|
||||||
continue OUTER_LOOP
|
continue OUTER_LOOP
|
||||||
} else if !blockMeta.PartsHeader.Equals(prs.ProposalBlockPartsHeader) {
|
} else if !blockMeta.BlockID.PartsHeader.Equals(prs.ProposalBlockPartsHeader) {
|
||||||
log.Info("Peer ProposalBlockPartsHeader mismatch, sleeping",
|
log.Info("Peer ProposalBlockPartsHeader mismatch, sleeping",
|
||||||
"peerHeight", prs.Height, "blockPartsHeader", blockMeta.PartsHeader, "peerBlockPartsHeader", prs.ProposalBlockPartsHeader)
|
"peerHeight", prs.Height, "blockPartsHeader", blockMeta.BlockID.PartsHeader, "peerBlockPartsHeader", prs.ProposalBlockPartsHeader)
|
||||||
time.Sleep(peerGossipSleepDuration)
|
time.Sleep(peerGossipSleepDuration)
|
||||||
continue OUTER_LOOP
|
continue OUTER_LOOP
|
||||||
}
|
}
|
||||||
@ -425,7 +425,7 @@ OUTER_LOOP:
|
|||||||
part := conR.conS.blockStore.LoadBlockPart(prs.Height, index)
|
part := conR.conS.blockStore.LoadBlockPart(prs.Height, index)
|
||||||
if part == nil {
|
if part == nil {
|
||||||
log.Warn("Could not load part", "index", index,
|
log.Warn("Could not load part", "index", index,
|
||||||
"peerHeight", prs.Height, "blockPartsHeader", blockMeta.PartsHeader, "peerBlockPartsHeader", prs.ProposalBlockPartsHeader)
|
"peerHeight", prs.Height, "blockPartsHeader", blockMeta.BlockID.PartsHeader, "peerBlockPartsHeader", prs.ProposalBlockPartsHeader)
|
||||||
time.Sleep(peerGossipSleepDuration)
|
time.Sleep(peerGossipSleepDuration)
|
||||||
continue OUTER_LOOP
|
continue OUTER_LOOP
|
||||||
}
|
}
|
||||||
|
@ -56,14 +56,16 @@ func Commit(height int) (*ctypes.ResultCommit, error) {
|
|||||||
return nil, fmt.Errorf("Height must be less than or equal to the current blockchain height")
|
return nil, fmt.Errorf("Height must be less than or equal to the current blockchain height")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
header := blockStore.LoadBlockMeta(height).Header
|
||||||
|
|
||||||
// If the next block has not been committed yet,
|
// If the next block has not been committed yet,
|
||||||
// use a non-canonical commit
|
// use a non-canonical commit
|
||||||
if height == storeHeight+1 {
|
if height == storeHeight+1 {
|
||||||
commit := blockStore.LoadSeenCommit(height)
|
commit := blockStore.LoadSeenCommit(height)
|
||||||
return &ctypes.ResultCommit{commit, false}, nil
|
return &ctypes.ResultCommit{header, commit, false}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the canonical commit (comes from the block at height+1)
|
// Return the canonical commit (comes from the block at height+1)
|
||||||
commit := blockStore.LoadBlockCommit(height)
|
commit := blockStore.LoadBlockCommit(height)
|
||||||
return &ctypes.ResultCommit{commit, true}, nil
|
return &ctypes.ResultCommit{header, commit, true}, nil
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ func Status() (*ctypes.ResultStatus, error) {
|
|||||||
)
|
)
|
||||||
if latestHeight != 0 {
|
if latestHeight != 0 {
|
||||||
latestBlockMeta = blockStore.LoadBlockMeta(latestHeight)
|
latestBlockMeta = blockStore.LoadBlockMeta(latestHeight)
|
||||||
latestBlockHash = latestBlockMeta.Hash
|
latestBlockHash = latestBlockMeta.BlockID.Hash
|
||||||
latestAppHash = latestBlockMeta.Header.AppHash
|
latestAppHash = latestBlockMeta.Header.AppHash
|
||||||
latestBlockTime = latestBlockMeta.Header.Time.UnixNano()
|
latestBlockTime = latestBlockMeta.Header.Time.UnixNano()
|
||||||
}
|
}
|
||||||
|
@ -24,8 +24,9 @@ type ResultBlock struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ResultCommit struct {
|
type ResultCommit struct {
|
||||||
|
Header *types.Header `json:"header"`
|
||||||
Commit *types.Commit `json:"commit"`
|
Commit *types.Commit `json:"commit"`
|
||||||
Canonical bool `json:"canonical"`
|
CanonicalCommit bool `json:"canonical"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ResultStatus struct {
|
type ResultStatus struct {
|
||||||
|
@ -6,12 +6,12 @@ import (
|
|||||||
|
|
||||||
"github.com/ebuchman/fail-test"
|
"github.com/ebuchman/fail-test"
|
||||||
|
|
||||||
|
abci "github.com/tendermint/abci/types"
|
||||||
. "github.com/tendermint/go-common"
|
. "github.com/tendermint/go-common"
|
||||||
cfg "github.com/tendermint/go-config"
|
cfg "github.com/tendermint/go-config"
|
||||||
"github.com/tendermint/go-crypto"
|
"github.com/tendermint/go-crypto"
|
||||||
"github.com/tendermint/tendermint/proxy"
|
"github.com/tendermint/tendermint/proxy"
|
||||||
"github.com/tendermint/tendermint/types"
|
"github.com/tendermint/tendermint/types"
|
||||||
abci "github.com/tendermint/abci/types"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -393,7 +393,7 @@ func (h *Handshaker) ReplayBlocks(appHash []byte, appBlockHeight int, appConnCon
|
|||||||
var eventCache types.Fireable // nil
|
var eventCache types.Fireable // nil
|
||||||
|
|
||||||
// replay the latest block
|
// replay the latest block
|
||||||
return h.state.ApplyBlock(eventCache, appConnConsensus, block, blockMeta.PartsHeader, MockMempool{})
|
return h.state.ApplyBlock(eventCache, appConnConsensus, block, blockMeta.BlockID.PartsHeader, MockMempool{})
|
||||||
} else if storeBlockHeight != stateBlockHeight {
|
} else if storeBlockHeight != stateBlockHeight {
|
||||||
// unless we failed before committing or saving state (previous 2 case),
|
// unless we failed before committing or saving state (previous 2 case),
|
||||||
// the store and state should be at the same height!
|
// the store and state should be at the same height!
|
||||||
|
@ -8,12 +8,12 @@ import (
|
|||||||
|
|
||||||
"github.com/tendermint/tendermint/config/tendermint_test"
|
"github.com/tendermint/tendermint/config/tendermint_test"
|
||||||
// . "github.com/tendermint/go-common"
|
// . "github.com/tendermint/go-common"
|
||||||
|
"github.com/tendermint/abci/example/dummy"
|
||||||
cfg "github.com/tendermint/go-config"
|
cfg "github.com/tendermint/go-config"
|
||||||
"github.com/tendermint/go-crypto"
|
"github.com/tendermint/go-crypto"
|
||||||
dbm "github.com/tendermint/go-db"
|
dbm "github.com/tendermint/go-db"
|
||||||
"github.com/tendermint/tendermint/proxy"
|
"github.com/tendermint/tendermint/proxy"
|
||||||
"github.com/tendermint/tendermint/types"
|
"github.com/tendermint/tendermint/types"
|
||||||
"github.com/tendermint/abci/example/dummy"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -203,8 +203,7 @@ func (bs *mockBlockStore) LoadBlock(height int) *types.Block { return bs.chain[h
|
|||||||
func (bs *mockBlockStore) LoadBlockMeta(height int) *types.BlockMeta {
|
func (bs *mockBlockStore) LoadBlockMeta(height int) *types.BlockMeta {
|
||||||
block := bs.chain[height-1]
|
block := bs.chain[height-1]
|
||||||
return &types.BlockMeta{
|
return &types.BlockMeta{
|
||||||
Hash: block.Hash(),
|
BlockID: types.BlockID{block.Hash(), block.MakePartSet(bs.config.GetInt("block_part_size")).Header()},
|
||||||
Header: block.Header,
|
Header: block.Header,
|
||||||
PartsHeader: block.MakePartSet(bs.config.GetInt("block_part_size")).Header(),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,15 +1,13 @@
|
|||||||
package types
|
package types
|
||||||
|
|
||||||
type BlockMeta struct {
|
type BlockMeta struct {
|
||||||
Hash []byte `json:"hash"` // The block hash
|
BlockID BlockID `json:"block_id"` // the block hash and partsethash
|
||||||
Header *Header `json:"header"` // The block's Header
|
Header *Header `json:"header"` // The block's Header
|
||||||
PartsHeader PartSetHeader `json:"parts_header"` // The PartSetHeader, for transfer
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewBlockMeta(block *Block, blockParts *PartSet) *BlockMeta {
|
func NewBlockMeta(block *Block, blockParts *PartSet) *BlockMeta {
|
||||||
return &BlockMeta{
|
return &BlockMeta{
|
||||||
Hash: block.Hash(),
|
BlockID: BlockID{block.Hash(), blockParts.Header()},
|
||||||
Header: block.Header,
|
Header: block.Header,
|
||||||
PartsHeader: blockParts.Header(),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user