mirror of
https://github.com/fluencelabs/tendermint
synced 2025-04-25 06:42:16 +00:00
make Block Header and Data non-pointers
make BlockMeta Header a non-pointer Refs #693
This commit is contained in:
parent
bbf2bd1d81
commit
270659f03f
@ -80,7 +80,7 @@ func TestBasic(t *testing.T) {
|
|||||||
}
|
}
|
||||||
// Request desired, pretend like we got the block immediately.
|
// Request desired, pretend like we got the block immediately.
|
||||||
go func() {
|
go func() {
|
||||||
block := &types.Block{Header: &types.Header{Height: request.Height}}
|
block := &types.Block{Header: types.Header{Height: request.Height}}
|
||||||
pool.AddBlock(request.PeerID, block, 123)
|
pool.AddBlock(request.PeerID, block, 123)
|
||||||
t.Logf("Added block from peer %v (height: %v)", request.PeerID, request.Height)
|
t.Logf("Added block from peer %v (height: %v)", request.PeerID, request.Height)
|
||||||
}()
|
}()
|
||||||
|
@ -126,7 +126,7 @@ func TestBlockStoreSaveLoadBlock(t *testing.T) {
|
|||||||
eraseSeenCommitInDB bool
|
eraseSeenCommitInDB bool
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
block: newBlock(&header1, commitAtH10),
|
block: newBlock(header1, commitAtH10),
|
||||||
parts: validPartSet,
|
parts: validPartSet,
|
||||||
seenCommit: seenCommit1,
|
seenCommit: seenCommit1,
|
||||||
},
|
},
|
||||||
@ -137,19 +137,19 @@ func TestBlockStoreSaveLoadBlock(t *testing.T) {
|
|||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
block: newBlock(&header2, commitAtH10),
|
block: newBlock(header2, commitAtH10),
|
||||||
parts: uncontiguousPartSet,
|
parts: uncontiguousPartSet,
|
||||||
wantPanic: "only save contiguous blocks", // and incomplete and uncontiguous parts
|
wantPanic: "only save contiguous blocks", // and incomplete and uncontiguous parts
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
block: newBlock(&header1, commitAtH10),
|
block: newBlock(header1, commitAtH10),
|
||||||
parts: incompletePartSet,
|
parts: incompletePartSet,
|
||||||
wantPanic: "only save complete block", // incomplete parts
|
wantPanic: "only save complete block", // incomplete parts
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
block: newBlock(&header1, commitAtH10),
|
block: newBlock(header1, commitAtH10),
|
||||||
parts: validPartSet,
|
parts: validPartSet,
|
||||||
seenCommit: seenCommit1,
|
seenCommit: seenCommit1,
|
||||||
corruptCommitInDB: true, // Corrupt the DB's commit entry
|
corruptCommitInDB: true, // Corrupt the DB's commit entry
|
||||||
@ -157,7 +157,7 @@ func TestBlockStoreSaveLoadBlock(t *testing.T) {
|
|||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
block: newBlock(&header1, commitAtH10),
|
block: newBlock(header1, commitAtH10),
|
||||||
parts: validPartSet,
|
parts: validPartSet,
|
||||||
seenCommit: seenCommit1,
|
seenCommit: seenCommit1,
|
||||||
wantPanic: "unmarshal to types.BlockMeta failed",
|
wantPanic: "unmarshal to types.BlockMeta failed",
|
||||||
@ -165,7 +165,7 @@ func TestBlockStoreSaveLoadBlock(t *testing.T) {
|
|||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
block: newBlock(&header1, commitAtH10),
|
block: newBlock(header1, commitAtH10),
|
||||||
parts: validPartSet,
|
parts: validPartSet,
|
||||||
seenCommit: seenCommit1,
|
seenCommit: seenCommit1,
|
||||||
|
|
||||||
@ -174,7 +174,7 @@ func TestBlockStoreSaveLoadBlock(t *testing.T) {
|
|||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
block: newBlock(&header1, commitAtH10),
|
block: newBlock(header1, commitAtH10),
|
||||||
parts: validPartSet,
|
parts: validPartSet,
|
||||||
seenCommit: seenCommit1,
|
seenCommit: seenCommit1,
|
||||||
|
|
||||||
@ -183,7 +183,7 @@ func TestBlockStoreSaveLoadBlock(t *testing.T) {
|
|||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
block: newBlock(&header1, commitAtH10),
|
block: newBlock(header1, commitAtH10),
|
||||||
parts: validPartSet,
|
parts: validPartSet,
|
||||||
seenCommit: seenCommit1,
|
seenCommit: seenCommit1,
|
||||||
|
|
||||||
@ -375,7 +375,7 @@ func doFn(fn func() (interface{}, error)) (res interface{}, err error, panicErr
|
|||||||
return res, err, panicErr
|
return res, err, panicErr
|
||||||
}
|
}
|
||||||
|
|
||||||
func newBlock(hdr *types.Header, lastCommit *types.Commit) *types.Block {
|
func newBlock(hdr types.Header, lastCommit *types.Commit) *types.Block {
|
||||||
return &types.Block{
|
return &types.Block{
|
||||||
Header: hdr,
|
Header: hdr,
|
||||||
LastCommit: lastCommit,
|
LastCommit: lastCommit,
|
||||||
|
@ -4,10 +4,11 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/tendermint/go-amino"
|
amino "github.com/tendermint/go-amino"
|
||||||
|
|
||||||
"github.com/tendermint/tendermint/crypto"
|
"github.com/tendermint/tendermint/crypto"
|
||||||
"github.com/tendermint/tendermint/types"
|
|
||||||
cmn "github.com/tendermint/tendermint/libs/common"
|
cmn "github.com/tendermint/tendermint/libs/common"
|
||||||
|
"github.com/tendermint/tendermint/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
func BenchmarkRoundStateDeepCopy(b *testing.B) {
|
func BenchmarkRoundStateDeepCopy(b *testing.B) {
|
||||||
@ -38,7 +39,7 @@ func BenchmarkRoundStateDeepCopy(b *testing.B) {
|
|||||||
}
|
}
|
||||||
// Random block
|
// Random block
|
||||||
block := &types.Block{
|
block := &types.Block{
|
||||||
Header: &types.Header{
|
Header: types.Header{
|
||||||
ChainID: cmn.RandStr(12),
|
ChainID: cmn.RandStr(12),
|
||||||
Time: time.Now(),
|
Time: time.Now(),
|
||||||
LastBlockID: blockID,
|
LastBlockID: blockID,
|
||||||
@ -50,7 +51,7 @@ func BenchmarkRoundStateDeepCopy(b *testing.B) {
|
|||||||
LastResultsHash: cmn.RandBytes(20),
|
LastResultsHash: cmn.RandBytes(20),
|
||||||
EvidenceHash: cmn.RandBytes(20),
|
EvidenceHash: cmn.RandBytes(20),
|
||||||
},
|
},
|
||||||
Data: &types.Data{
|
Data: types.Data{
|
||||||
Txs: txs,
|
Txs: txs,
|
||||||
},
|
},
|
||||||
Evidence: types.EvidenceData{},
|
Evidence: types.EvidenceData{},
|
||||||
|
@ -15,14 +15,14 @@ func ValidateBlockMeta(meta *types.BlockMeta, check lite.Commit) error {
|
|||||||
return errors.New("expecting a non-nil BlockMeta")
|
return errors.New("expecting a non-nil BlockMeta")
|
||||||
}
|
}
|
||||||
// TODO: check the BlockID??
|
// TODO: check the BlockID??
|
||||||
return ValidateHeader(meta.Header, check)
|
return ValidateHeader(&meta.Header, check)
|
||||||
}
|
}
|
||||||
|
|
||||||
func ValidateBlock(meta *types.Block, check lite.Commit) error {
|
func ValidateBlock(meta *types.Block, check lite.Commit) error {
|
||||||
if meta == nil {
|
if meta == nil {
|
||||||
return errors.New("expecting a non-nil Block")
|
return errors.New("expecting a non-nil Block")
|
||||||
}
|
}
|
||||||
err := ValidateHeader(meta.Header, check)
|
err := ValidateHeader(&meta.Header, check)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ var (
|
|||||||
testTime2 = time.Date(2017, 1, 2, 1, 1, 1, 1, time.UTC)
|
testTime2 = time.Date(2017, 1, 2, 1, 1, 1, 1, time.UTC)
|
||||||
)
|
)
|
||||||
|
|
||||||
var hdrHeight11 = &types.Header{
|
var hdrHeight11 = types.Header{
|
||||||
Height: 11,
|
Height: 11,
|
||||||
Time: testTime1,
|
Time: testTime1,
|
||||||
ValidatorsHash: []byte("Tendermint"),
|
ValidatorsHash: []byte("Tendermint"),
|
||||||
@ -34,21 +34,18 @@ func TestValidateBlock(t *testing.T) {
|
|||||||
block: nil, wantErr: "non-nil Block",
|
block: nil, wantErr: "non-nil Block",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
block: &types.Block{}, wantErr: "nil Header",
|
block: &types.Block{},
|
||||||
},
|
|
||||||
{
|
|
||||||
block: &types.Block{Header: new(types.Header)},
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// Start Header.Height mismatch test
|
// Start Header.Height mismatch test
|
||||||
{
|
{
|
||||||
block: &types.Block{Header: &types.Header{Height: 10}},
|
block: &types.Block{Header: types.Header{Height: 10}},
|
||||||
commit: lite.Commit{Header: &types.Header{Height: 11}},
|
commit: lite.Commit{Header: &types.Header{Height: 11}},
|
||||||
wantErr: "don't match - 10 vs 11",
|
wantErr: "don't match - 10 vs 11",
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
block: &types.Block{Header: &types.Header{Height: 11}},
|
block: &types.Block{Header: types.Header{Height: 11}},
|
||||||
commit: lite.Commit{Header: &types.Header{Height: 11}},
|
commit: lite.Commit{Header: &types.Header{Height: 11}},
|
||||||
},
|
},
|
||||||
// End Header.Height mismatch test
|
// End Header.Height mismatch test
|
||||||
@ -62,15 +59,15 @@ func TestValidateBlock(t *testing.T) {
|
|||||||
|
|
||||||
{
|
{
|
||||||
block: &types.Block{Header: hdrHeight11},
|
block: &types.Block{Header: hdrHeight11},
|
||||||
commit: lite.Commit{Header: hdrHeight11},
|
commit: lite.Commit{Header: &hdrHeight11},
|
||||||
},
|
},
|
||||||
// End Header.Hash mismatch test
|
// End Header.Hash mismatch test
|
||||||
|
|
||||||
// Start Header.Data hash mismatch test
|
// Start Header.Data hash mismatch test
|
||||||
{
|
{
|
||||||
block: &types.Block{
|
block: &types.Block{
|
||||||
Header: &types.Header{Height: 11},
|
Header: types.Header{Height: 11},
|
||||||
Data: &types.Data{Txs: []types.Tx{[]byte("0xDE"), []byte("AD")}},
|
Data: types.Data{Txs: []types.Tx{[]byte("0xDE"), []byte("AD")}},
|
||||||
},
|
},
|
||||||
commit: lite.Commit{
|
commit: lite.Commit{
|
||||||
Header: &types.Header{Height: 11},
|
Header: &types.Header{Height: 11},
|
||||||
@ -80,8 +77,8 @@ func TestValidateBlock(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
block: &types.Block{
|
block: &types.Block{
|
||||||
Header: &types.Header{Height: 11, DataHash: deadBeefHash},
|
Header: types.Header{Height: 11, DataHash: deadBeefHash},
|
||||||
Data: &types.Data{Txs: deadBeefTxs},
|
Data: types.Data{Txs: deadBeefTxs},
|
||||||
},
|
},
|
||||||
commit: lite.Commit{
|
commit: lite.Commit{
|
||||||
Header: &types.Header{Height: 11},
|
Header: &types.Header{Height: 11},
|
||||||
@ -116,21 +113,18 @@ func TestValidateBlockMeta(t *testing.T) {
|
|||||||
meta: nil, wantErr: "non-nil BlockMeta",
|
meta: nil, wantErr: "non-nil BlockMeta",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
meta: &types.BlockMeta{}, wantErr: "non-nil Header",
|
meta: &types.BlockMeta{},
|
||||||
},
|
|
||||||
{
|
|
||||||
meta: &types.BlockMeta{Header: new(types.Header)},
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// Start Header.Height mismatch test
|
// Start Header.Height mismatch test
|
||||||
{
|
{
|
||||||
meta: &types.BlockMeta{Header: &types.Header{Height: 10}},
|
meta: &types.BlockMeta{Header: types.Header{Height: 10}},
|
||||||
commit: lite.Commit{Header: &types.Header{Height: 11}},
|
commit: lite.Commit{Header: &types.Header{Height: 11}},
|
||||||
wantErr: "don't match - 10 vs 11",
|
wantErr: "don't match - 10 vs 11",
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
meta: &types.BlockMeta{Header: &types.Header{Height: 11}},
|
meta: &types.BlockMeta{Header: types.Header{Height: 11}},
|
||||||
commit: lite.Commit{Header: &types.Header{Height: 11}},
|
commit: lite.Commit{Header: &types.Header{Height: 11}},
|
||||||
},
|
},
|
||||||
// End Header.Height mismatch test
|
// End Header.Height mismatch test
|
||||||
@ -144,12 +138,12 @@ func TestValidateBlockMeta(t *testing.T) {
|
|||||||
|
|
||||||
{
|
{
|
||||||
meta: &types.BlockMeta{Header: hdrHeight11},
|
meta: &types.BlockMeta{Header: hdrHeight11},
|
||||||
commit: lite.Commit{Header: hdrHeight11},
|
commit: lite.Commit{Header: &hdrHeight11},
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
meta: &types.BlockMeta{
|
meta: &types.BlockMeta{
|
||||||
Header: &types.Header{
|
Header: types.Header{
|
||||||
Height: 11,
|
Height: 11,
|
||||||
ValidatorsHash: []byte("lite-test"),
|
ValidatorsHash: []byte("lite-test"),
|
||||||
// TODO: should be able to use empty time after Amino upgrade
|
// TODO: should be able to use empty time after Amino upgrade
|
||||||
@ -164,7 +158,7 @@ func TestValidateBlockMeta(t *testing.T) {
|
|||||||
|
|
||||||
{
|
{
|
||||||
meta: &types.BlockMeta{
|
meta: &types.BlockMeta{
|
||||||
Header: &types.Header{
|
Header: types.Header{
|
||||||
Height: 11, DataHash: deadBeefHash,
|
Height: 11, DataHash: deadBeefHash,
|
||||||
ValidatorsHash: []byte("Tendermint"),
|
ValidatorsHash: []byte("Tendermint"),
|
||||||
Time: testTime1,
|
Time: testTime1,
|
||||||
@ -183,7 +177,7 @@ func TestValidateBlockMeta(t *testing.T) {
|
|||||||
|
|
||||||
{
|
{
|
||||||
meta: &types.BlockMeta{
|
meta: &types.BlockMeta{
|
||||||
Header: &types.Header{
|
Header: types.Header{
|
||||||
Height: 11, DataHash: deadBeefHash,
|
Height: 11, DataHash: deadBeefHash,
|
||||||
ValidatorsHash: []byte("Tendermint"),
|
ValidatorsHash: []byte("Tendermint"),
|
||||||
Time: testTime2,
|
Time: testTime2,
|
||||||
|
@ -3,10 +3,10 @@ package core
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
cmn "github.com/tendermint/tendermint/libs/common"
|
||||||
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
||||||
sm "github.com/tendermint/tendermint/state"
|
sm "github.com/tendermint/tendermint/state"
|
||||||
"github.com/tendermint/tendermint/types"
|
"github.com/tendermint/tendermint/types"
|
||||||
cmn "github.com/tendermint/tendermint/libs/common"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Get block headers for minHeight <= height <= maxHeight.
|
// Get block headers for minHeight <= height <= maxHeight.
|
||||||
@ -288,12 +288,12 @@ func Commit(heightPtr *int64) (*ctypes.ResultCommit, error) {
|
|||||||
// use a non-canonical commit
|
// use a non-canonical commit
|
||||||
if height == storeHeight {
|
if height == storeHeight {
|
||||||
commit := blockStore.LoadSeenCommit(height)
|
commit := blockStore.LoadSeenCommit(height)
|
||||||
return ctypes.NewResultCommit(header, commit, false), nil
|
return ctypes.NewResultCommit(&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.NewResultCommit(header, commit, true), nil
|
return ctypes.NewResultCommit(&header, commit, true), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// BlockResults gets ABCIResults at a given height.
|
// BlockResults gets ABCIResults at a given height.
|
||||||
|
@ -86,7 +86,7 @@ func (blockExec *BlockExecutor) ApplyBlock(state State, blockID types.BlockID, b
|
|||||||
fail.Fail() // XXX
|
fail.Fail() // XXX
|
||||||
|
|
||||||
// update the state with the block and responses
|
// update the state with the block and responses
|
||||||
state, err = updateState(state, blockID, block.Header, abciResponses)
|
state, err = updateState(state, blockID, &block.Header, abciResponses)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return state, fmt.Errorf("Commit failed for application: %v", err)
|
return state, fmt.Errorf("Commit failed for application: %v", err)
|
||||||
}
|
}
|
||||||
@ -189,7 +189,7 @@ func execBlockOnProxyApp(logger log.Logger, proxyAppConn proxy.AppConnConsensus,
|
|||||||
// Begin block
|
// Begin block
|
||||||
_, err := proxyAppConn.BeginBlockSync(abci.RequestBeginBlock{
|
_, err := proxyAppConn.BeginBlockSync(abci.RequestBeginBlock{
|
||||||
Hash: block.Hash(),
|
Hash: block.Hash(),
|
||||||
Header: types.TM2PB.Header(block.Header),
|
Header: types.TM2PB.Header(&block.Header),
|
||||||
Validators: signVals,
|
Validators: signVals,
|
||||||
ByzantineValidators: byzVals,
|
ByzantineValidators: byzVals,
|
||||||
})
|
})
|
||||||
|
@ -219,7 +219,7 @@ func TestOneValidatorChangesSaveLoad(t *testing.T) {
|
|||||||
power++
|
power++
|
||||||
}
|
}
|
||||||
header, blockID, responses := makeHeaderPartsResponsesValPowerChange(state, i, power)
|
header, blockID, responses := makeHeaderPartsResponsesValPowerChange(state, i, power)
|
||||||
state, err = updateState(state, blockID, header, responses)
|
state, err = updateState(state, blockID, &header, responses)
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
nextHeight := state.LastBlockHeight + 1
|
nextHeight := state.LastBlockHeight + 1
|
||||||
saveValidatorsInfo(stateDB, nextHeight, state.LastHeightValidatorsChanged, state.Validators)
|
saveValidatorsInfo(stateDB, nextHeight, state.LastHeightValidatorsChanged, state.Validators)
|
||||||
@ -264,7 +264,7 @@ func TestManyValidatorChangesSaveLoad(t *testing.T) {
|
|||||||
// swap the first validator with a new one ^^^ (validator set size stays the same)
|
// swap the first validator with a new one ^^^ (validator set size stays the same)
|
||||||
header, blockID, responses := makeHeaderPartsResponsesValPubKeyChange(state, height, pubkey)
|
header, blockID, responses := makeHeaderPartsResponsesValPubKeyChange(state, height, pubkey)
|
||||||
var err error
|
var err error
|
||||||
state, err = updateState(state, blockID, header, responses)
|
state, err = updateState(state, blockID, &header, responses)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
nextHeight := state.LastBlockHeight + 1
|
nextHeight := state.LastBlockHeight + 1
|
||||||
saveValidatorsInfo(stateDB, nextHeight, state.LastHeightValidatorsChanged, state.Validators)
|
saveValidatorsInfo(stateDB, nextHeight, state.LastHeightValidatorsChanged, state.Validators)
|
||||||
@ -321,7 +321,7 @@ func TestConsensusParamsChangesSaveLoad(t *testing.T) {
|
|||||||
cp = params[changeIndex]
|
cp = params[changeIndex]
|
||||||
}
|
}
|
||||||
header, blockID, responses := makeHeaderPartsResponsesParams(state, i, cp)
|
header, blockID, responses := makeHeaderPartsResponsesParams(state, i, cp)
|
||||||
state, err = updateState(state, blockID, header, responses)
|
state, err = updateState(state, blockID, &header, responses)
|
||||||
|
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
nextHeight := state.LastBlockHeight + 1
|
nextHeight := state.LastBlockHeight + 1
|
||||||
@ -420,7 +420,7 @@ func TestApplyUpdates(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func makeHeaderPartsResponsesValPubKeyChange(state State, height int64,
|
func makeHeaderPartsResponsesValPubKeyChange(state State, height int64,
|
||||||
pubkey crypto.PubKey) (*types.Header, types.BlockID, *ABCIResponses) {
|
pubkey crypto.PubKey) (types.Header, types.BlockID, *ABCIResponses) {
|
||||||
|
|
||||||
block := makeBlock(state, height)
|
block := makeBlock(state, height)
|
||||||
abciResponses := &ABCIResponses{
|
abciResponses := &ABCIResponses{
|
||||||
@ -442,7 +442,7 @@ func makeHeaderPartsResponsesValPubKeyChange(state State, height int64,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func makeHeaderPartsResponsesValPowerChange(state State, height int64,
|
func makeHeaderPartsResponsesValPowerChange(state State, height int64,
|
||||||
power int64) (*types.Header, types.BlockID, *ABCIResponses) {
|
power int64) (types.Header, types.BlockID, *ABCIResponses) {
|
||||||
|
|
||||||
block := makeBlock(state, height)
|
block := makeBlock(state, height)
|
||||||
abciResponses := &ABCIResponses{
|
abciResponses := &ABCIResponses{
|
||||||
@ -463,7 +463,7 @@ func makeHeaderPartsResponsesValPowerChange(state State, height int64,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func makeHeaderPartsResponsesParams(state State, height int64,
|
func makeHeaderPartsResponsesParams(state State, height int64,
|
||||||
params types.ConsensusParams) (*types.Header, types.BlockID, *ABCIResponses) {
|
params types.ConsensusParams) (types.Header, types.BlockID, *ABCIResponses) {
|
||||||
|
|
||||||
block := makeBlock(state, height)
|
block := makeBlock(state, height)
|
||||||
abciResponses := &ABCIResponses{
|
abciResponses := &ABCIResponses{
|
||||||
@ -476,14 +476,3 @@ type paramsChangeTestCase struct {
|
|||||||
height int64
|
height int64
|
||||||
params types.ConsensusParams
|
params types.ConsensusParams
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeHeaderPartsResults(state State, height int64,
|
|
||||||
results []*abci.ResponseDeliverTx) (*types.Header, types.BlockID, *ABCIResponses) {
|
|
||||||
|
|
||||||
block := makeBlock(state, height)
|
|
||||||
abciResponses := &ABCIResponses{
|
|
||||||
DeliverTx: results,
|
|
||||||
EndBlock: &abci.ResponseEndBlock{},
|
|
||||||
}
|
|
||||||
return block.Header, types.BlockID{block.Hash(), types.PartSetHeader{}}, abciResponses
|
|
||||||
}
|
|
||||||
|
@ -134,7 +134,7 @@ func newBlockCallback(n *Node) em.EventCallbackFunc {
|
|||||||
n.logger.Info("new block", "height", block.Height, "numTxs", block.NumTxs)
|
n.logger.Info("new block", "height", block.Height, "numTxs", block.NumTxs)
|
||||||
|
|
||||||
if n.blockCh != nil {
|
if n.blockCh != nil {
|
||||||
n.blockCh <- *block
|
n.blockCh <- block
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ import (
|
|||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"github.com/tendermint/go-amino"
|
amino "github.com/tendermint/go-amino"
|
||||||
crypto "github.com/tendermint/tendermint/crypto"
|
crypto "github.com/tendermint/tendermint/crypto"
|
||||||
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
||||||
em "github.com/tendermint/tendermint/tools/tm-monitor/eventmeter"
|
em "github.com/tendermint/tendermint/tools/tm-monitor/eventmeter"
|
||||||
@ -33,11 +33,11 @@ func TestNodeNewBlockReceived(t *testing.T) {
|
|||||||
defer n.Stop()
|
defer n.Stop()
|
||||||
n.SendBlocksTo(blockCh)
|
n.SendBlocksTo(blockCh)
|
||||||
|
|
||||||
blockHeader := &tmtypes.Header{Height: 5}
|
blockHeader := tmtypes.Header{Height: 5}
|
||||||
emMock.Call("eventCallback", &em.EventMetric{}, tmtypes.EventDataNewBlockHeader{blockHeader})
|
emMock.Call("eventCallback", &em.EventMetric{}, tmtypes.EventDataNewBlockHeader{blockHeader})
|
||||||
|
|
||||||
assert.Equal(t, int64(5), n.Height)
|
assert.Equal(t, int64(5), n.Height)
|
||||||
assert.Equal(t, *blockHeader, <-blockCh)
|
assert.Equal(t, blockHeader, <-blockCh)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNodeNewBlockLatencyReceived(t *testing.T) {
|
func TestNodeNewBlockLatencyReceived(t *testing.T) {
|
||||||
|
@ -17,8 +17,8 @@ import (
|
|||||||
// TODO: add Version byte
|
// TODO: add Version byte
|
||||||
type Block struct {
|
type Block struct {
|
||||||
mtx sync.Mutex
|
mtx sync.Mutex
|
||||||
*Header `json:"header"`
|
Header `json:"header"`
|
||||||
*Data `json:"data"`
|
Data `json:"data"`
|
||||||
Evidence EvidenceData `json:"evidence"`
|
Evidence EvidenceData `json:"evidence"`
|
||||||
LastCommit *Commit `json:"last_commit"`
|
LastCommit *Commit `json:"last_commit"`
|
||||||
}
|
}
|
||||||
@ -27,15 +27,15 @@ type Block struct {
|
|||||||
// It populates the same set of fields validated by ValidateBasic
|
// It populates the same set of fields validated by ValidateBasic
|
||||||
func MakeBlock(height int64, txs []Tx, commit *Commit) *Block {
|
func MakeBlock(height int64, txs []Tx, commit *Commit) *Block {
|
||||||
block := &Block{
|
block := &Block{
|
||||||
Header: &Header{
|
Header: Header{
|
||||||
Height: height,
|
Height: height,
|
||||||
Time: time.Now(),
|
Time: time.Now(),
|
||||||
NumTxs: int64(len(txs)),
|
NumTxs: int64(len(txs)),
|
||||||
},
|
},
|
||||||
LastCommit: commit,
|
Data: Data{
|
||||||
Data: &Data{
|
|
||||||
Txs: txs,
|
Txs: txs,
|
||||||
},
|
},
|
||||||
|
LastCommit: commit,
|
||||||
}
|
}
|
||||||
block.fillHeader()
|
block.fillHeader()
|
||||||
return block
|
return block
|
||||||
@ -43,6 +43,9 @@ func MakeBlock(height int64, txs []Tx, commit *Commit) *Block {
|
|||||||
|
|
||||||
// AddEvidence appends the given evidence to the block
|
// AddEvidence appends the given evidence to the block
|
||||||
func (b *Block) AddEvidence(evidence []Evidence) {
|
func (b *Block) AddEvidence(evidence []Evidence) {
|
||||||
|
if b == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
b.Evidence.Evidence = append(b.Evidence.Evidence, evidence...)
|
b.Evidence.Evidence = append(b.Evidence.Evidence, evidence...)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,7 +101,7 @@ func (b *Block) Hash() cmn.HexBytes {
|
|||||||
b.mtx.Lock()
|
b.mtx.Lock()
|
||||||
defer b.mtx.Unlock()
|
defer b.mtx.Unlock()
|
||||||
|
|
||||||
if b == nil || b.Header == nil || b.Data == nil || b.LastCommit == nil {
|
if b == nil || b.LastCommit == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
b.fillHeader()
|
b.fillHeader()
|
||||||
|
@ -3,7 +3,7 @@ package types
|
|||||||
// BlockMeta contains meta information about a block - namely, it's ID and Header.
|
// BlockMeta contains meta information about a block - namely, it's ID and Header.
|
||||||
type BlockMeta struct {
|
type BlockMeta struct {
|
||||||
BlockID BlockID `json:"block_id"` // the block hash and partsethash
|
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
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewBlockMeta returns a new BlockMeta from the block and its blockParts.
|
// NewBlockMeta returns a new BlockMeta from the block and its blockParts.
|
||||||
|
@ -69,7 +69,7 @@ type EventDataNewBlock struct {
|
|||||||
|
|
||||||
// light weight event for benchmarking
|
// light weight event for benchmarking
|
||||||
type EventDataNewBlockHeader struct {
|
type EventDataNewBlockHeader struct {
|
||||||
Header *Header `json:"header"`
|
Header Header `json:"header"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// All txs fire EventDataTx
|
// All txs fire EventDataTx
|
||||||
|
Loading…
x
Reference in New Issue
Block a user