Merge pull request #1965 from tendermint/693-part-2

make Block Header and Data non-pointers
This commit is contained in:
Alexander Simmerl
2018-07-20 17:42:42 +02:00
committed by GitHub
13 changed files with 59 additions and 72 deletions
+9 -6
View File
@@ -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()
+1 -1
View File
@@ -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.
+1 -1
View File
@@ -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