From 9b90022c50606a8b8bb35067573222989d867d4a Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Thu, 3 Oct 2019 20:20:29 +0200 Subject: [PATCH] Improve logs and error messages License: MIT Signed-off-by: Jakub Sztandera --- chain/blocksync.go | 2 +- chain/sync.go | 22 ++++++++++------------ go.sum | 3 +++ 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/chain/blocksync.go b/chain/blocksync.go index 766fb4efb..2565b1335 100644 --- a/chain/blocksync.go +++ b/chain/blocksync.go @@ -349,7 +349,7 @@ func (bs *BlockSync) GetChainMessages(ctx context.Context, h *types.TipSet, coun } // TODO: What if we have no peers (and err is nil)? - return nil, xerrors.Errorf("GetChainMessages failed with all peers: %w", err) + return nil, xerrors.Errorf("GetChainMessages failed with all peers(%d): %w", len(peers), err) } func bstsToFullTipSet(bts *BSTipSet) (*store.FullTipSet, error) { diff --git a/chain/sync.go b/chain/sync.go index 0c224b84a..c9511c8c0 100644 --- a/chain/sync.go +++ b/chain/sync.go @@ -99,7 +99,7 @@ func (syncer *Syncer) InformNewHead(from peer.ID, fts *store.FullTipSet) { log.Debug("got block from ourselves") if err := syncer.Sync(fts); err != nil { - log.Errorf("failed to sync our own block: %s", err) + log.Errorf("failed to sync our own block: %+v", err) } return @@ -111,7 +111,7 @@ func (syncer *Syncer) InformNewHead(from peer.ID, fts *store.FullTipSet) { go func() { if err := syncer.Sync(fts); err != nil { - log.Errorf("sync error: %s", err) + log.Errorf("sync error: %+v", err) } }() } @@ -532,7 +532,7 @@ loop: // Most likely our peers aren't fully synced yet, but forwarded // new block message (ideally we'd find better peers) - log.Error("failed to get blocks: ", err) + log.Errorf("failed to get blocks: %+v", err) // This error will only be logged above, return nil, xerrors.Errorf("failed to get blocks: %w", err) @@ -570,9 +570,9 @@ loop: func (syncer *Syncer) syncMessagesAndCheckState(headers []*types.TipSet) error { syncer.syncState.SetHeight(0) return syncer.iterFullTipsets(headers, func(fts *store.FullTipSet) error { - log.Debugf("validating tipset (heigt=%d, size=%d)", fts.TipSet().Height(), len(fts.TipSet().Cids())) + log.Debugw("validating tipset", "height", fts.TipSet().Height(), "size", len(fts.TipSet().Cids())) if err := syncer.ValidateTipSet(context.TODO(), fts); err != nil { - log.Errorf("failed to validate tipset: %s", err) + log.Errorf("failed to validate tipset: %+v", err) return xerrors.Errorf("message processing failed: %w", err) } @@ -625,11 +625,9 @@ func (syncer *Syncer) iterFullTipsets(headers []*types.TipSet, cb func(*store.Fu bstip := bstips[len(bstips)-(bsi+1)] fts, err := zipTipSetAndMessages(blks, this, bstip.BlsMessages, bstip.SecpkMessages, bstip.BlsMsgIncludes, bstip.SecpkMsgIncludes) if err != nil { - log.Warn("zipping failed: ", err, bsi, i) - log.Warn("height: ", this.Height()) - log.Warn("bstip height: ", bstip.Blocks[0].Height) - log.Warn("bstips: ", bstips) - log.Warn("next height: ", i+batchSize) + log.Warnw("zipping failed", "error", err, "bsi", bsi, "i", i, + "height", this.Height(), "bstip-height", bstip.Blocks[0].Height, + "bstips", bstips, "next-height", i+batchSize) return xerrors.Errorf("message processing failed: %w", err) } @@ -655,7 +653,7 @@ func persistMessages(bs bstore.Blockstore, bst *BSTipSet) error { for _, m := range bst.BlsMessages { //log.Infof("putting BLS message: %s", m.Cid()) if _, err := store.PutMessage(bs, m); err != nil { - log.Error("failed to persist messages: ", err) + log.Errorf("failed to persist messages: %+v", err) return xerrors.Errorf("BLS message processing failed: %w", err) } } @@ -665,7 +663,7 @@ func persistMessages(bs bstore.Blockstore, bst *BSTipSet) error { } //log.Infof("putting secp256k1 message: %s", m.Cid()) if _, err := store.PutMessage(bs, m); err != nil { - log.Error("failed to persist messages: ", err) + log.Errorf("failed to persist messages: %+v", err) return xerrors.Errorf("secp256k1 message processing failed: %w", err) } } diff --git a/go.sum b/go.sum index 8240534b4..abbe9d439 100644 --- a/go.sum +++ b/go.sum @@ -75,6 +75,7 @@ github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25Kn github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs= github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1:+020luEh2TKB4/GOp8oxxtq0Daoen/Cii55CzbTV6DU= github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I= +github.com/fatih/color v1.6.0 h1:66qjqZk8kalYAvDRtM1AdAJQI0tj4Wrue3Eq3B3pmFU= github.com/fatih/color v1.6.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/filecoin-project/go-amt-ipld v0.0.0-20190919045431-3650716fff16 h1:NzojcJU1VbS6zdLG13JMYis/cQy/MrN3rxmZRq56jKA= github.com/filecoin-project/go-amt-ipld v0.0.0-20190919045431-3650716fff16/go.mod h1:lKjJYPg2kwbav5f78i5YA8kGccnZn18IySbpneXvaQs= @@ -439,11 +440,13 @@ github.com/marten-seemann/qtls v0.2.3 h1:0yWJ43C62LsZt08vuQJDK1uC1czUc3FJeCLPoNA github.com/marten-seemann/qtls v0.2.3/go.mod h1:xzjG7avBwGGbdZ8dTGxlBnLArsVKLvwmjgmPuiQEcYk= github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcnceauSikq3lYCQ= +github.com/mattn/go-colorable v0.1.2 h1:/bC9yWikZXAL9uJdulbSfyVNIR3n3trXl+v8+1sx8mU= github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-isatty v0.0.5/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= +github.com/mattn/go-isatty v0.0.9 h1:d5US/mDsogSGW37IV293h//ZFaeajb69h+EHFsv2xGg= github.com/mattn/go-isatty v0.0.9/go.mod h1:YNRxwqDuOph6SZLI9vUUz6OYw3QyUt7WiY2yME+cCiQ= github.com/mattn/go-runewidth v0.0.4 h1:2BvfKmzob6Bmd4YsL0zygOqfdFnK7GR4QL06Do4/p7Y= github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=