@ -19,7 +19,8 @@ import (
type Block struct {
* Header ` json:"header" `
* Data ` json:"data" `
LastCommit * Commit ` json:"last_commit" `
Evidence EvidenceData ` json:"evidence" `
LastCommit * Commit ` json:"last_commit" `
}
// MakeBlock returns a new block with an empty header, except what can be computed from itself.
@ -40,6 +41,11 @@ func MakeBlock(height int64, txs []Tx, commit *Commit) *Block {
return block
}
// AddEvidence appends the given evidence to the block
func ( b * Block ) AddEvidence ( evidence [ ] Evidence ) {
b . Evidence . Evidence = append ( b . Evidence . Evidence , evidence ... )
}
// ValidateBasic performs basic validation that doesn't involve state data.
// It checks the internal consistency of the block.
func ( b * Block ) ValidateBasic ( ) error {
@ -58,6 +64,9 @@ func (b *Block) ValidateBasic() error {
if ! bytes . Equal ( b . DataHash , b . Data . Hash ( ) ) {
return fmt . Errorf ( "Wrong Block.Header.DataHash. Expected %v, got %v" , b . DataHash , b . Data . Hash ( ) )
}
if ! bytes . Equal ( b . EvidenceHash , b . Evidence . Hash ( ) ) {
return errors . New ( cmn . Fmt ( "Wrong Block.Header.EvidenceHash. Expected %v, got %v" , b . EvidenceHash , b . Evidence . Hash ( ) ) )
}
return nil
}
@ -69,6 +78,9 @@ func (b *Block) FillHeader() {
if b . DataHash == nil {
b . DataHash = b . Data . Hash ( )
}
if b . EvidenceHash == nil {
b . EvidenceHash = b . Evidence . Hash ( )
}
}
// Hash computes and returns the block hash.
@ -114,9 +126,11 @@ func (b *Block) StringIndented(indent string) string {
% s % v
% s % v
% s % v
% s % v
% s } # % v ` ,
indent , b . Header . StringIndented ( indent + " " ) ,
indent , b . Data . StringIndented ( indent + " " ) ,
indent , b . Evidence . StringIndented ( indent + " " ) ,
indent , b . LastCommit . StringIndented ( indent + " " ) ,
indent , b . Hash ( ) )
}
@ -134,6 +148,7 @@ func (b *Block) StringShort() string {
// Header defines the structure of a Tendermint block header
// TODO: limit header size
// NOTE: changes to the Header should be duplicated in the abci Header
type Header struct {
// basic block info
ChainID string ` json:"chain_id" `
@ -154,6 +169,9 @@ type Header struct {
ConsensusHash data . Bytes ` json:"consensus_hash" ` // consensus params for current block
AppHash data . Bytes ` json:"app_hash" ` // state after txs from the previous block
LastResultsHash data . Bytes ` json:"last_results_hash" ` // root hash of all results from the txs from the previous block
// consensus info
EvidenceHash data . Bytes ` json:"evidence_hash" ` // evidence included in the block
}
// Hash returns the hash of the header.
@ -175,6 +193,7 @@ func (h *Header) Hash() data.Bytes {
"App" : h . AppHash ,
"Consensus" : h . ConsensusHash ,
"Results" : h . LastResultsHash ,
"Evidence" : h . EvidenceHash ,
} )
}
@ -196,6 +215,7 @@ func (h *Header) StringIndented(indent string) string {
% s App : % v
% s Conensus : % v
% s Results : % v
% s Evidence : % v
% s } # % v ` ,
indent , h . ChainID ,
indent , h . Height ,
@ -209,6 +229,7 @@ func (h *Header) StringIndented(indent string) string {
indent , h . AppHash ,
indent , h . ConsensusHash ,
indent , h . LastResultsHash ,
indent , h . EvidenceHash ,
indent , h . Hash ( ) )
}
@ -413,6 +434,33 @@ func (data *Data) StringIndented(indent string) string {
indent , data . hash )
}
//-----------------------------------------------------------------------------
// EvidenceData contains any evidence of malicious wrong-doing by validators
type EvidenceData struct {
Evidence [ ] Evidence ` json:"evidence" `
// Volatile
hash data . Bytes
}
// Hash returns the hash of the data
func ( data * EvidenceData ) Hash ( ) data . Bytes {
if data . hash == nil {
// TODO
}
return data . hash
}
// StringIndented returns a string representation of the transactions
func ( data * EvidenceData ) StringIndented ( indent string ) string {
if data == nil {
return "nil-Data"
}
// TODO
return ""
}
//--------------------------------------------------------------------------------
// BlockID defines the unique ID of a block as its Hash and its PartSetHeader