diff --git a/blockchain/pool_test.go b/blockchain/pool_test.go index dcb046db..01187bcf 100644 --- a/blockchain/pool_test.go +++ b/blockchain/pool_test.go @@ -79,7 +79,7 @@ func TestBasic(t *testing.T) { } // Request desired, pretend like we got the block immediately. 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) t.Logf("Added block from peer %v (height: %v)", request.PeerID, request.Height) }() diff --git a/blockchain/store_test.go b/blockchain/store_test.go index 888040bd..c8165400 100644 --- a/blockchain/store_test.go +++ b/blockchain/store_test.go @@ -126,7 +126,7 @@ func TestBlockStoreSaveLoadBlock(t *testing.T) { eraseSeenCommitInDB bool }{ { - block: newBlock(&header1, commitAtH10), + block: newBlock(header1, commitAtH10), parts: validPartSet, seenCommit: seenCommit1, }, @@ -137,19 +137,19 @@ func TestBlockStoreSaveLoadBlock(t *testing.T) { }, { - block: newBlock(&header2, commitAtH10), + block: newBlock(header2, commitAtH10), parts: uncontiguousPartSet, wantPanic: "only save contiguous blocks", // and incomplete and uncontiguous parts }, { - block: newBlock(&header1, commitAtH10), + block: newBlock(header1, commitAtH10), parts: incompletePartSet, wantPanic: "only save complete block", // incomplete parts }, { - block: newBlock(&header1, commitAtH10), + block: newBlock(header1, commitAtH10), parts: validPartSet, seenCommit: seenCommit1, 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, seenCommit: seenCommit1, 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, seenCommit: seenCommit1, @@ -174,7 +174,7 @@ func TestBlockStoreSaveLoadBlock(t *testing.T) { }, { - block: newBlock(&header1, commitAtH10), + block: newBlock(header1, commitAtH10), parts: validPartSet, seenCommit: seenCommit1, @@ -183,7 +183,7 @@ func TestBlockStoreSaveLoadBlock(t *testing.T) { }, { - block: newBlock(&header1, commitAtH10), + block: newBlock(header1, commitAtH10), parts: validPartSet, seenCommit: seenCommit1, @@ -375,7 +375,7 @@ func doFn(fn func() (interface{}, error)) (res interface{}, err error, 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{ Header: hdr, LastCommit: lastCommit, diff --git a/consensus/types/round_state_test.go b/consensus/types/round_state_test.go index 080178f2..b6ce0396 100644 --- a/consensus/types/round_state_test.go +++ b/consensus/types/round_state_test.go @@ -4,10 +4,11 @@ import ( "testing" "time" - "github.com/tendermint/go-amino" + amino "github.com/tendermint/go-amino" + "github.com/tendermint/tendermint/crypto" - "github.com/tendermint/tendermint/types" cmn "github.com/tendermint/tendermint/libs/common" + "github.com/tendermint/tendermint/types" ) func BenchmarkRoundStateDeepCopy(b *testing.B) { @@ -38,7 +39,7 @@ func BenchmarkRoundStateDeepCopy(b *testing.B) { } // Random block block := &types.Block{ - Header: &types.Header{ + Header: types.Header{ ChainID: cmn.RandStr(12), Time: time.Now(), LastBlockID: blockID, @@ -50,7 +51,7 @@ func BenchmarkRoundStateDeepCopy(b *testing.B) { LastResultsHash: cmn.RandBytes(20), EvidenceHash: cmn.RandBytes(20), }, - Data: &types.Data{ + Data: types.Data{ Txs: txs, }, Evidence: types.EvidenceData{}, diff --git a/lite/proxy/block.go b/lite/proxy/block.go index 4cff9ee6..00b8c87f 100644 --- a/lite/proxy/block.go +++ b/lite/proxy/block.go @@ -15,14 +15,14 @@ func ValidateBlockMeta(meta *types.BlockMeta, check lite.Commit) error { return errors.New("expecting a non-nil BlockMeta") } // TODO: check the BlockID?? - return ValidateHeader(meta.Header, check) + return ValidateHeader(&meta.Header, check) } func ValidateBlock(meta *types.Block, check lite.Commit) error { if meta == nil { return errors.New("expecting a non-nil Block") } - err := ValidateHeader(meta.Header, check) + err := ValidateHeader(&meta.Header, check) if err != nil { return err } diff --git a/lite/proxy/validate_test.go b/lite/proxy/validate_test.go index 782a6aab..47c0ff6d 100644 --- a/lite/proxy/validate_test.go +++ b/lite/proxy/validate_test.go @@ -18,7 +18,7 @@ var ( testTime2 = time.Date(2017, 1, 2, 1, 1, 1, 1, time.UTC) ) -var hdrHeight11 = &types.Header{ +var hdrHeight11 = types.Header{ Height: 11, Time: testTime1, ValidatorsHash: []byte("Tendermint"), @@ -34,21 +34,18 @@ func TestValidateBlock(t *testing.T) { block: nil, wantErr: "non-nil Block", }, { - block: &types.Block{}, wantErr: "nil Header", - }, - { - block: &types.Block{Header: new(types.Header)}, + block: &types.Block{}, }, // 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}}, 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}}, }, // End Header.Height mismatch test @@ -62,15 +59,15 @@ func TestValidateBlock(t *testing.T) { { block: &types.Block{Header: hdrHeight11}, - commit: lite.Commit{Header: hdrHeight11}, + commit: lite.Commit{Header: &hdrHeight11}, }, // End Header.Hash mismatch test // Start Header.Data hash mismatch test { block: &types.Block{ - Header: &types.Header{Height: 11}, - Data: &types.Data{Txs: []types.Tx{[]byte("0xDE"), []byte("AD")}}, + Header: types.Header{Height: 11}, + Data: types.Data{Txs: []types.Tx{[]byte("0xDE"), []byte("AD")}}, }, commit: lite.Commit{ Header: &types.Header{Height: 11}, @@ -80,8 +77,8 @@ func TestValidateBlock(t *testing.T) { }, { block: &types.Block{ - Header: &types.Header{Height: 11, DataHash: deadBeefHash}, - Data: &types.Data{Txs: deadBeefTxs}, + Header: types.Header{Height: 11, DataHash: deadBeefHash}, + Data: types.Data{Txs: deadBeefTxs}, }, commit: lite.Commit{ Header: &types.Header{Height: 11}, @@ -116,21 +113,18 @@ func TestValidateBlockMeta(t *testing.T) { meta: nil, wantErr: "non-nil BlockMeta", }, { - meta: &types.BlockMeta{}, wantErr: "non-nil Header", - }, - { - meta: &types.BlockMeta{Header: new(types.Header)}, + meta: &types.BlockMeta{}, }, // 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}}, 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}}, }, // End Header.Height mismatch test @@ -144,12 +138,12 @@ func TestValidateBlockMeta(t *testing.T) { { meta: &types.BlockMeta{Header: hdrHeight11}, - commit: lite.Commit{Header: hdrHeight11}, + commit: lite.Commit{Header: &hdrHeight11}, }, { meta: &types.BlockMeta{ - Header: &types.Header{ + Header: types.Header{ Height: 11, ValidatorsHash: []byte("lite-test"), // TODO: should be able to use empty time after Amino upgrade @@ -164,7 +158,7 @@ func TestValidateBlockMeta(t *testing.T) { { meta: &types.BlockMeta{ - Header: &types.Header{ + Header: types.Header{ Height: 11, DataHash: deadBeefHash, ValidatorsHash: []byte("Tendermint"), Time: testTime1, @@ -183,7 +177,7 @@ func TestValidateBlockMeta(t *testing.T) { { meta: &types.BlockMeta{ - Header: &types.Header{ + Header: types.Header{ Height: 11, DataHash: deadBeefHash, ValidatorsHash: []byte("Tendermint"), Time: testTime2, diff --git a/rpc/core/blocks.go b/rpc/core/blocks.go index 0e887315..5815b60e 100644 --- a/rpc/core/blocks.go +++ b/rpc/core/blocks.go @@ -3,10 +3,10 @@ package core import ( "fmt" + cmn "github.com/tendermint/tendermint/libs/common" ctypes "github.com/tendermint/tendermint/rpc/core/types" sm "github.com/tendermint/tendermint/state" "github.com/tendermint/tendermint/types" - cmn "github.com/tendermint/tendermint/libs/common" ) // Get block headers for minHeight <= height <= maxHeight. @@ -288,12 +288,12 @@ func Commit(heightPtr *int64) (*ctypes.ResultCommit, error) { // use a non-canonical commit if height == storeHeight { 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) 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. diff --git a/state/execution.go b/state/execution.go index 601abec9..f38f5e0b 100644 --- a/state/execution.go +++ b/state/execution.go @@ -86,7 +86,7 @@ func (blockExec *BlockExecutor) ApplyBlock(state State, blockID types.BlockID, b fail.Fail() // XXX // 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 { return state, fmt.Errorf("Commit failed for application: %v", err) } @@ -189,7 +189,7 @@ func execBlockOnProxyApp(logger log.Logger, proxyAppConn proxy.AppConnConsensus, // Begin block _, err := proxyAppConn.BeginBlockSync(abci.RequestBeginBlock{ Hash: block.Hash(), - Header: types.TM2PB.Header(block.Header), + Header: types.TM2PB.Header(&block.Header), Validators: signVals, ByzantineValidators: byzVals, }) diff --git a/state/state_test.go b/state/state_test.go index bf0c910f..c15a2e0c 100644 --- a/state/state_test.go +++ b/state/state_test.go @@ -219,7 +219,7 @@ func TestOneValidatorChangesSaveLoad(t *testing.T) { 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) nextHeight := state.LastBlockHeight + 1 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) header, blockID, responses := makeHeaderPartsResponsesValPubKeyChange(state, height, pubkey) var err error - state, err = updateState(state, blockID, header, responses) + state, err = updateState(state, blockID, &header, responses) require.Nil(t, err) nextHeight := state.LastBlockHeight + 1 saveValidatorsInfo(stateDB, nextHeight, state.LastHeightValidatorsChanged, state.Validators) @@ -321,7 +321,7 @@ func TestConsensusParamsChangesSaveLoad(t *testing.T) { cp = params[changeIndex] } 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) nextHeight := state.LastBlockHeight + 1 @@ -420,7 +420,7 @@ func TestApplyUpdates(t *testing.T) { } 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) abciResponses := &ABCIResponses{ @@ -442,7 +442,7 @@ func makeHeaderPartsResponsesValPubKeyChange(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) abciResponses := &ABCIResponses{ @@ -463,7 +463,7 @@ func makeHeaderPartsResponsesValPowerChange(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) abciResponses := &ABCIResponses{ @@ -476,14 +476,3 @@ type paramsChangeTestCase struct { height int64 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 -} diff --git a/tools/tm-monitor/monitor/node.go b/tools/tm-monitor/monitor/node.go index 7dc6d747..b9987020 100644 --- a/tools/tm-monitor/monitor/node.go +++ b/tools/tm-monitor/monitor/node.go @@ -134,7 +134,7 @@ func newBlockCallback(n *Node) em.EventCallbackFunc { n.logger.Info("new block", "height", block.Height, "numTxs", block.NumTxs) if n.blockCh != nil { - n.blockCh <- *block + n.blockCh <- block } } } diff --git a/tools/tm-monitor/monitor/node_test.go b/tools/tm-monitor/monitor/node_test.go index e97b2de4..8c0fc888 100644 --- a/tools/tm-monitor/monitor/node_test.go +++ b/tools/tm-monitor/monitor/node_test.go @@ -6,7 +6,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/tendermint/go-amino" + amino "github.com/tendermint/go-amino" crypto "github.com/tendermint/tendermint/crypto" ctypes "github.com/tendermint/tendermint/rpc/core/types" em "github.com/tendermint/tendermint/tools/tm-monitor/eventmeter" @@ -33,11 +33,11 @@ func TestNodeNewBlockReceived(t *testing.T) { defer n.Stop() n.SendBlocksTo(blockCh) - blockHeader := &tmtypes.Header{Height: 5} + blockHeader := tmtypes.Header{Height: 5} emMock.Call("eventCallback", &em.EventMetric{}, tmtypes.EventDataNewBlockHeader{blockHeader}) assert.Equal(t, int64(5), n.Height) - assert.Equal(t, *blockHeader, <-blockCh) + assert.Equal(t, blockHeader, <-blockCh) } func TestNodeNewBlockLatencyReceived(t *testing.T) { diff --git a/types/block.go b/types/block.go index e23fd71d..48857076 100644 --- a/types/block.go +++ b/types/block.go @@ -17,8 +17,8 @@ import ( // TODO: add Version byte type Block struct { mtx sync.Mutex - *Header `json:"header"` - *Data `json:"data"` + Header `json:"header"` + Data `json:"data"` Evidence EvidenceData `json:"evidence"` LastCommit *Commit `json:"last_commit"` } @@ -27,15 +27,15 @@ type Block struct { // It populates the same set of fields validated by ValidateBasic func MakeBlock(height int64, txs []Tx, commit *Commit) *Block { block := &Block{ - Header: &Header{ + Header: Header{ Height: height, Time: time.Now(), NumTxs: int64(len(txs)), }, - LastCommit: commit, - Data: &Data{ + Data: Data{ Txs: txs, }, + LastCommit: commit, } block.fillHeader() return block @@ -43,6 +43,9 @@ func MakeBlock(height int64, txs []Tx, commit *Commit) *Block { // AddEvidence appends the given evidence to the block func (b *Block) AddEvidence(evidence []Evidence) { + if b == nil { + return + } b.Evidence.Evidence = append(b.Evidence.Evidence, evidence...) } @@ -98,7 +101,7 @@ func (b *Block) Hash() cmn.HexBytes { b.mtx.Lock() defer b.mtx.Unlock() - if b == nil || b.Header == nil || b.Data == nil || b.LastCommit == nil { + if b == nil || b.LastCommit == nil { return nil } b.fillHeader() diff --git a/types/block_meta.go b/types/block_meta.go index 6dd502e4..d8926af0 100644 --- a/types/block_meta.go +++ b/types/block_meta.go @@ -3,7 +3,7 @@ package types // BlockMeta contains meta information about a block - namely, it's ID and Header. type BlockMeta struct { 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. diff --git a/types/events.go b/types/events.go index 891c6a90..c26fecb7 100644 --- a/types/events.go +++ b/types/events.go @@ -64,7 +64,7 @@ type EventDataNewBlock struct { // light weight event for benchmarking type EventDataNewBlockHeader struct { - Header *Header `json:"header"` + Header Header `json:"header"` } // All txs fire EventDataTx