libs/common: Refactor libs/common 4 (#4237)

* libs/common: Refactor libs/common 4

- move byte function out of cmn to its own pkg
- move tempfile out of cmn to its own pkg
- move throttletimer to its own pkg

ref #4147

Signed-off-by: Marko Baricevic <marbar3778@yahoo.com>

* add changelog entry

* fix linting issues
This commit is contained in:
Marko
2019-12-11 23:16:35 +01:00
committed by GitHub
parent 15e80d2448
commit 89f0bbbd76
50 changed files with 181 additions and 251 deletions
+22 -21
View File
@@ -12,6 +12,7 @@ import (
"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto/merkle"
"github.com/tendermint/tendermint/crypto/tmhash"
tmbytes "github.com/tendermint/tendermint/libs/bytes"
cmn "github.com/tendermint/tendermint/libs/common"
"github.com/tendermint/tendermint/version"
)
@@ -156,7 +157,7 @@ func (b *Block) fillHeader() {
// Hash computes and returns the block hash.
// If the block is incomplete, block hash is nil for safety.
func (b *Block) Hash() cmn.HexBytes {
func (b *Block) Hash() tmbytes.HexBytes {
if b == nil {
return nil
}
@@ -329,20 +330,20 @@ type Header struct {
LastBlockID BlockID `json:"last_block_id"`
// hashes of block data
LastCommitHash cmn.HexBytes `json:"last_commit_hash"` // commit from validators from the last block
DataHash cmn.HexBytes `json:"data_hash"` // transactions
LastCommitHash tmbytes.HexBytes `json:"last_commit_hash"` // commit from validators from the last block
DataHash tmbytes.HexBytes `json:"data_hash"` // transactions
// hashes from the app output from the prev block
ValidatorsHash cmn.HexBytes `json:"validators_hash"` // validators for the current block
NextValidatorsHash cmn.HexBytes `json:"next_validators_hash"` // validators for the next block
ConsensusHash cmn.HexBytes `json:"consensus_hash"` // consensus params for current block
AppHash cmn.HexBytes `json:"app_hash"` // state after txs from the previous block
ValidatorsHash tmbytes.HexBytes `json:"validators_hash"` // validators for the current block
NextValidatorsHash tmbytes.HexBytes `json:"next_validators_hash"` // validators for the next block
ConsensusHash tmbytes.HexBytes `json:"consensus_hash"` // consensus params for current block
AppHash tmbytes.HexBytes `json:"app_hash"` // state after txs from the previous block
// root hash of all results from the txs from the previous block
LastResultsHash cmn.HexBytes `json:"last_results_hash"`
LastResultsHash tmbytes.HexBytes `json:"last_results_hash"`
// consensus info
EvidenceHash cmn.HexBytes `json:"evidence_hash"` // evidence included in the block
ProposerAddress Address `json:"proposer_address"` // original proposer of the block
EvidenceHash tmbytes.HexBytes `json:"evidence_hash"` // evidence included in the block
ProposerAddress Address `json:"proposer_address"` // original proposer of the block
}
// Populate the Header with state-derived data.
@@ -372,7 +373,7 @@ func (h *Header) Populate(
// Returns nil if ValidatorHash is missing,
// since a Header is not valid unless there is
// a ValidatorsHash (corresponding to the validator set).
func (h *Header) Hash() cmn.HexBytes {
func (h *Header) Hash() tmbytes.HexBytes {
if h == nil || len(h.ValidatorsHash) == 0 {
return nil
}
@@ -479,8 +480,8 @@ func (cs CommitSig) Absent() bool {
func (cs CommitSig) String() string {
return fmt.Sprintf("CommitSig{%X by %X on %v @ %s}",
cmn.Fingerprint(cs.Signature),
cmn.Fingerprint(cs.ValidatorAddress),
tmbytes.Fingerprint(cs.Signature),
tmbytes.Fingerprint(cs.ValidatorAddress),
cs.BlockIDFlag,
CanonicalTime(cs.Timestamp))
}
@@ -559,7 +560,7 @@ type Commit struct {
// Memoized in first call to corresponding method.
// NOTE: can't memoize in constructor because constructor isn't used for
// unmarshaling.
hash cmn.HexBytes
hash tmbytes.HexBytes
bitArray *cmn.BitArray
}
@@ -696,7 +697,7 @@ func (commit *Commit) ValidateBasic() error {
}
// Hash returns the hash of the commit
func (commit *Commit) Hash() cmn.HexBytes {
func (commit *Commit) Hash() tmbytes.HexBytes {
if commit == nil {
return nil
}
@@ -809,11 +810,11 @@ type Data struct {
Txs Txs `json:"txs"`
// Volatile
hash cmn.HexBytes
hash tmbytes.HexBytes
}
// Hash returns the hash of the data
func (data *Data) Hash() cmn.HexBytes {
func (data *Data) Hash() tmbytes.HexBytes {
if data == nil {
return (Txs{}).Hash()
}
@@ -850,11 +851,11 @@ type EvidenceData struct {
Evidence EvidenceList `json:"evidence"`
// Volatile
hash cmn.HexBytes
hash tmbytes.HexBytes
}
// Hash returns the hash of the data.
func (data *EvidenceData) Hash() cmn.HexBytes {
func (data *EvidenceData) Hash() tmbytes.HexBytes {
if data.hash == nil {
data.hash = data.Evidence.Hash()
}
@@ -885,8 +886,8 @@ func (data *EvidenceData) StringIndented(indent string) string {
// BlockID defines the unique ID of a block as its Hash and its PartSetHeader
type BlockID struct {
Hash cmn.HexBytes `json:"hash"`
PartsHeader PartSetHeader `json:"parts"`
Hash tmbytes.HexBytes `json:"hash"`
PartsHeader PartSetHeader `json:"parts"`
}
// Equals returns true if the BlockID matches the given BlockID