From 1f7491df37caf974ffa0c824c4c02a8fe2aafcd9 Mon Sep 17 00:00:00 2001 From: Mission Liao Date: Fri, 19 Oct 2018 18:39:17 +0800 Subject: core: initial commit for logger (#228) * Replace "log.*" with logger. * Add simple logger to log with log package. * Add debug logs to all calls to these interfaces: - core.Application - core.Governance - core.Network * Add Stringer to these types: - types.DKGComplaint - types.AgreementResult - types.DKGMasterPublicKey - types.DKGFinalize --- core/types/block-randomness.go | 7 +++++++ core/types/dkg.go | 17 +++++++++++++++++ core/types/position.go | 9 ++++++++- 3 files changed, 32 insertions(+), 1 deletion(-) (limited to 'core/types') diff --git a/core/types/block-randomness.go b/core/types/block-randomness.go index b101e22..ebffd2b 100644 --- a/core/types/block-randomness.go +++ b/core/types/block-randomness.go @@ -18,6 +18,8 @@ package types import ( + "fmt" + "github.com/dexon-foundation/dexon-consensus-core/common" ) @@ -28,6 +30,11 @@ type AgreementResult struct { Votes []Vote `json:"votes"` } +func (r *AgreementResult) String() string { + return fmt.Sprintf( + "agreementResult[%s:%s]", r.BlockHash, &r.Position) +} + // BlockRandomnessResult describes a block randomness result type BlockRandomnessResult struct { BlockHash common.Hash `json:"block_hash"` diff --git a/core/types/dkg.go b/core/types/dkg.go index c13740b..6018ebd 100644 --- a/core/types/dkg.go +++ b/core/types/dkg.go @@ -53,6 +53,12 @@ type DKGMasterPublicKey struct { Signature crypto.Signature `json:"signature"` } +func (d *DKGMasterPublicKey) String() string { + return fmt.Sprintf("MasterPublicKey[%s:%d]", + d.ProposerID.String()[:6], + d.Round) +} + // NewDKGMasterPublicKey returns a new DKGMasterPublicKey instance. func NewDKGMasterPublicKey() *DKGMasterPublicKey { return &DKGMasterPublicKey{ @@ -75,6 +81,11 @@ type DKGComplaint struct { Signature crypto.Signature `json:"signature"` } +func (c *DKGComplaint) String() string { + return fmt.Sprintf("DKGComplaint[%s:%d]%s", + c.ProposerID.String()[:6], c.Round, &c.PrivateShare) +} + // DKGPartialSignature describe a partial signature in DKG protocol. type DKGPartialSignature struct { ProposerID NodeID `json:"proposer_id"` @@ -91,6 +102,12 @@ type DKGFinalize struct { Signature crypto.Signature `json:"signature"` } +func (final *DKGFinalize) String() string { + return fmt.Sprintf("DKGFinal[%s:%d]", + final.ProposerID.String()[:6], + final.Round) +} + // IsNack returns true if it's a nack complaint in DKG protocol. func (c *DKGComplaint) IsNack() bool { return len(c.PrivateShare.Signature.Signature) == 0 diff --git a/core/types/position.go b/core/types/position.go index 4e254ba..51de405 100644 --- a/core/types/position.go +++ b/core/types/position.go @@ -17,7 +17,10 @@ package types -import "errors" +import ( + "errors" + "fmt" +) // ErrComparePositionOnDifferentChains raised when attempting to // compare two positions with different chain ID. @@ -31,6 +34,10 @@ type Position struct { Height uint64 `json:"height"` } +func (pos *Position) String() string { + return fmt.Sprintf("pos[%d:%d:%d]", pos.ChainID, pos.Round, pos.Height) +} + // Equal checks if two positions are equal, it panics when their chainIDs // are different. func (pos *Position) Equal(other *Position) bool { -- cgit v1.2.3