diff --git a/account/priv_account.go b/account/priv_account.go index f9179ec84..5ef64ec9a 100644 --- a/account/priv_account.go +++ b/account/priv_account.go @@ -23,3 +23,7 @@ func GenPrivAccount() *PrivAccount { func (privAccount *PrivAccount) Sign(o Signable) Signature { return privAccount.PrivKey.Sign(SignBytes(o)) } + +func (privAccount *PrivAccount) String() string { + return Fmt("PrivAccount{%X}", privAccount.Address) +} diff --git a/account/privkey.go b/account/privkey.go index 5d9f49b74..ad233d9a9 100644 --- a/account/privkey.go +++ b/account/privkey.go @@ -5,6 +5,7 @@ import ( "github.com/tendermint/go-ed25519" "github.com/tendermint/tendermint/binary" + . "github.com/tendermint/tendermint/common" ) // PrivKey is part of PrivAccount and state.PrivValidator. @@ -46,3 +47,7 @@ func (key PrivKeyEd25519) Sign(msg []byte) Signature { func (key PrivKeyEd25519) PubKey() PubKey { return PubKeyEd25519(ed25519.MakePubKey(key)) } + +func (key PrivKeyEd25519) String() string { + return Fmt("PrivKeyEd25519{*****}") +} diff --git a/account/pubkey.go b/account/pubkey.go index f38c3e1a6..1a9f1c92a 100644 --- a/account/pubkey.go +++ b/account/pubkey.go @@ -5,6 +5,7 @@ import ( "github.com/tendermint/go-ed25519" "github.com/tendermint/tendermint/binary" + . "github.com/tendermint/tendermint/common" ) // PubKey is part of Account and Validator. @@ -42,6 +43,10 @@ func (key PubKeyNil) VerifyBytes(msg []byte, sig_ Signature) bool { panic("PubKeyNil cannot verify messages") } +func (key PubKeyNil) String() string { + return "PubKeyNil{}" +} + //------------------------------------- // Implements PubKey @@ -71,3 +76,7 @@ func (key PubKeyEd25519) VerifyBytes(msg []byte, sig_ Signature) bool { } return ed25519.VerifyBatch([]*ed25519.Verify{v1}) } + +func (key PubKeyEd25519) String() string { + return Fmt("PubKeyEd25519{%X}", []byte(key)) +} diff --git a/block/tx.go b/block/tx.go index e9bec43be..d4d5fb6fd 100644 --- a/block/tx.go +++ b/block/tx.go @@ -6,6 +6,7 @@ import ( "github.com/tendermint/tendermint/account" "github.com/tendermint/tendermint/binary" + . "github.com/tendermint/tendermint/common" ) var ( @@ -82,6 +83,10 @@ func (txIn *TxInput) WriteSignBytes(w io.Writer, n *int64, err *error) { binary.WriteUvarint(txIn.Sequence, w, n, err) } +func (txIn *TxInput) String() string { + return Fmt("TxInput{%X,%v,%v,%v,%v}", txIn.Address, txIn.Amount, txIn.Sequence, txIn.Signature, txIn.PubKey) +} + //----------------------------------------------------------------------------- type TxOutput struct { @@ -104,6 +109,10 @@ func (txOut *TxOutput) WriteSignBytes(w io.Writer, n *int64, err *error) { binary.WriteUint64(txOut.Amount, w, n, err) } +func (txOut *TxOutput) String() string { + return Fmt("TxOutput{%X,%v}", txOut.Address, txOut.Amount) +} + //----------------------------------------------------------------------------- type SendTx struct { @@ -124,6 +133,10 @@ func (tx *SendTx) WriteSignBytes(w io.Writer, n *int64, err *error) { } } +func (tx *SendTx) String() string { + return Fmt("SendTx{%v -> %v}", tx.Inputs, tx.Outputs) +} + //----------------------------------------------------------------------------- type BondTx struct { @@ -146,6 +159,10 @@ func (tx *BondTx) WriteSignBytes(w io.Writer, n *int64, err *error) { } } +func (tx *BondTx) String() string { + return Fmt("BondTx{%v: %v -> %v}", tx.PubKey, tx.Inputs, tx.UnbondTo) +} + //----------------------------------------------------------------------------- type UnbondTx struct { @@ -161,6 +178,10 @@ func (tx *UnbondTx) WriteSignBytes(w io.Writer, n *int64, err *error) { binary.WriteUvarint(tx.Height, w, n, err) } +func (tx *UnbondTx) String() string { + return Fmt("UnbondTx{%X,%v,%v}", tx.Address, tx.Height, tx.Signature) +} + //----------------------------------------------------------------------------- type RebondTx struct { @@ -176,6 +197,10 @@ func (tx *RebondTx) WriteSignBytes(w io.Writer, n *int64, err *error) { binary.WriteUvarint(tx.Height, w, n, err) } +func (tx *RebondTx) String() string { + return Fmt("RebondTx{%X,%v,%v}", tx.Address, tx.Height, tx.Signature) +} + //----------------------------------------------------------------------------- type DupeoutTx struct { @@ -189,3 +214,7 @@ func (tx *DupeoutTx) TypeByte() byte { return TxTypeDupeout } func (tx *DupeoutTx) WriteSignBytes(w io.Writer, n *int64, err *error) { panic("DupeoutTx has no sign bytes") } + +func (tx *DupeoutTx) String() string { + return Fmt("DupeoutTx{%X,%v,%v}", tx.Address, tx.VoteA, tx.VoteB) +} diff --git a/common/repeat_timer.go b/common/repeat_timer.go index 5973d148a..de9b71fae 100644 --- a/common/repeat_timer.go +++ b/common/repeat_timer.go @@ -7,16 +7,17 @@ RepeatTimer repeatedly sends a struct{}{} to .Ch after each "dur" period. It's good for keeping connections alive. */ type RepeatTimer struct { + Name string Ch chan struct{} quit chan struct{} dur time.Duration timer *time.Timer } -func NewRepeatTimer(dur time.Duration) *RepeatTimer { +func NewRepeatTimer(name string, dur time.Duration) *RepeatTimer { var ch = make(chan struct{}) var quit = make(chan struct{}) - var t = &RepeatTimer{Ch: ch, dur: dur, quit: quit} + var t = &RepeatTimer{Name: name, Ch: ch, dur: dur, quit: quit} t.timer = time.AfterFunc(dur, t.fireRoutine) return t } @@ -26,6 +27,9 @@ func (t *RepeatTimer) fireRoutine() { case t.Ch <- struct{}{}: t.timer.Reset(t.dur) case <-t.quit: + // do nothing + default: + t.timer.Reset(t.dur) } } diff --git a/common/throttle_timer.go b/common/throttle_timer.go index 74843e28d..c1c012a01 100644 --- a/common/throttle_timer.go +++ b/common/throttle_timer.go @@ -12,6 +12,7 @@ If a long continuous burst of .Set() calls happens, ThrottleTimer fires at most once every "dur". */ type ThrottleTimer struct { + Name string Ch chan struct{} quit chan struct{} dur time.Duration @@ -19,10 +20,10 @@ type ThrottleTimer struct { isSet uint32 } -func NewThrottleTimer(dur time.Duration) *ThrottleTimer { +func NewThrottleTimer(name string, dur time.Duration) *ThrottleTimer { var ch = make(chan struct{}) var quit = make(chan struct{}) - var t = &ThrottleTimer{Ch: ch, dur: dur, quit: quit} + var t = &ThrottleTimer{Name: name, Ch: ch, dur: dur, quit: quit} t.timer = time.AfterFunc(dur, t.fireRoutine) t.timer.Stop() return t @@ -33,6 +34,9 @@ func (t *ThrottleTimer) fireRoutine() { case t.Ch <- struct{}{}: atomic.StoreUint32(&t.isSet, 0) case <-t.quit: + // do nothing + default: + t.timer.Reset(t.dur) } } diff --git a/p2p/connection.go b/p2p/connection.go index 2cb3c5160..edb4389da 100644 --- a/p2p/connection.go +++ b/p2p/connection.go @@ -93,12 +93,12 @@ func NewMConnection(conn net.Conn, chDescs []*ChannelDescriptor, onReceive recei recvMonitor: flow.New(0, 0), sendRate: defaultSendRate, recvRate: defaultRecvRate, - flushTimer: NewThrottleTimer(flushThrottleMS * time.Millisecond), + flushTimer: NewThrottleTimer("flush", flushThrottleMS*time.Millisecond), send: make(chan struct{}, 1), quit: make(chan struct{}), - pingTimer: NewRepeatTimer(pingTimeoutMinutes * time.Minute), + pingTimer: NewRepeatTimer("ping", pingTimeoutMinutes*time.Minute), pong: make(chan struct{}), - chStatsTimer: NewRepeatTimer(updateStatsSeconds * time.Second), + chStatsTimer: NewRepeatTimer("chStats", updateStatsSeconds*time.Second), onReceive: onReceive, onError: onError, LocalAddress: NewNetAddress(conn.LocalAddr()), diff --git a/p2p/pex_reactor.go b/p2p/pex_reactor.go index 88372e7ae..bca70370a 100644 --- a/p2p/pex_reactor.go +++ b/p2p/pex_reactor.go @@ -133,7 +133,7 @@ func (pexR *PEXReactor) ensurePeersRoutine() { // fire once immediately. pexR.ensurePeers() // fire periodically - timer := NewRepeatTimer(ensurePeersPeriodSeconds * time.Second) + timer := NewRepeatTimer("pex", ensurePeersPeriodSeconds*time.Second) FOR_LOOP: for { select {