Skip to content

Commit

Permalink
chore: better logging by renaming err to error (#681)
Browse files Browse the repository at this point in the history
  • Loading branch information
themantre authored Sep 10, 2023
1 parent 54a0f9e commit 673e5cc
Show file tree
Hide file tree
Showing 24 changed files with 61 additions and 61 deletions.
2 changes: 1 addition & 1 deletion consensus/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func (s *commitState) decide() {
cert := s.makeCertificate(votes)
err := s.state.CommitBlock(s.height, certBlock, cert)
if err != nil {
s.logger.Error("committing block failed", "block", certBlock, "err", err)
s.logger.Error("committing block failed", "block", certBlock, "error", err)
} else {
s.logger.Info("block committed, schedule new height", "hash", certBlock.Hash().ShortString())
}
Expand Down
10 changes: 5 additions & 5 deletions consensus/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,12 +226,12 @@ func (cs *consensus) SetProposal(p *proposal.Proposal) {
} else {
proposer := cs.proposer(p.Round())
if err := p.Verify(proposer.PublicKey()); err != nil {
cs.logger.Warn("proposal has invalid signature", "proposal", p, "err", err)
cs.logger.Warn("proposal has invalid signature", "proposal", p, "error", err)
return
}

if err := cs.state.ValidateBlock(p.Block()); err != nil {
cs.logger.Warn("invalid block", "proposal", p, "err", err)
cs.logger.Warn("invalid block", "proposal", p, "error", err)
return
}
}
Expand Down Expand Up @@ -280,7 +280,7 @@ func (cs *consensus) AddVote(v *vote.Vote) {
v.Type() == vote.VoteTypeCPMainVote {
err := cs.checkJust(v)
if err != nil {
cs.logger.Error("error on adding a cp vote", "vote", v, "err", err)
cs.logger.Error("error on adding a cp vote", "vote", v, "error", err)
return
}

Expand All @@ -307,7 +307,7 @@ func (cs *consensus) AddVote(v *vote.Vote) {

added, err := cs.log.AddVote(v)
if err != nil {
cs.logger.Error("error on adding a vote", "vote", v, "err", err)
cs.logger.Error("error on adding a vote", "vote", v, "error", err)
}
if added {
cs.logger.Debug("new vote added", "vote", v)
Expand Down Expand Up @@ -650,7 +650,7 @@ func (cs *consensus) signAddVote(v *vote.Vote) {

_, err := cs.log.AddVote(v)
if err != nil {
cs.logger.Error("error on adding our vote", "err", err, "vote", v)
cs.logger.Error("error on adding our vote", "error", err, "vote", v)
}
cs.broadcastVote(v)
}
Expand Down
2 changes: 1 addition & 1 deletion consensus/height.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (s *newHeightState) decide() {
lastCert := s.makeCertificate(votes)
if lastCert != nil {
if err := s.state.UpdateLastCertificate(lastCert); err != nil {
s.logger.Warn("updating last certificate failed", "err", err)
s.logger.Warn("updating last certificate failed", "error", err)
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions consensus/propose.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ func (s *proposeState) decide() {
func (s *proposeState) createProposal(height uint32, round int16) {
block, err := s.state.ProposeBlock(s.signer, s.rewardAddr, round)
if err != nil {
s.logger.Error("unable to propose a block!", "err", err)
s.logger.Error("unable to propose a block!", "error", err)
return
}
if err := s.state.ValidateBlock(block); err != nil {
s.logger.Error("proposed block is invalid!", "err", err)
s.logger.Error("proposed block is invalid!", "error", err)
return
}

Expand Down
6 changes: 3 additions & 3 deletions network/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func newBootstrap(ctx context.Context, h lp2phost.Host, d lp2pnet.Dialer, r lp2p

addresses, err := PeerAddrsToAddrInfo(conf.Addresses)
if err != nil {
b.logger.Panic("couldn't parse bootstrap addresses", "err", err, "addresses", conf.Addresses)
b.logger.Panic("couldn't parse bootstrap addresses", "error", err, "addresses", conf.Addresses)
}
b.bootstrapPeers = addresses

Expand Down Expand Up @@ -122,7 +122,7 @@ func (b *bootstrap) checkConnectivity() {
}

if err := b.host.Connect(b.ctx, pi); err != nil {
b.logger.Error("error trying to connect to bootstrap node", "info", pi, "err", err)
b.logger.Error("error trying to connect to bootstrap node", "info", pi, "error", err)
}
}

Expand All @@ -149,6 +149,6 @@ func (b *bootstrap) expand() {

err := dht.Bootstrap(b.ctx)
if err != nil {
b.logger.Warn("peer discovery may suffer", "err", err)
b.logger.Warn("peer discovery may suffer", "error", err)
}
}
4 changes: 2 additions & 2 deletions network/dht.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func newDHTService(ctx context.Context, host lp2phost.Host, protocolID lp2pcore.

kademlia, err := lp2pdht.New(ctx, host, opts...)
if err != nil {
logger.Panic("unable to start DHT service", "err", err)
logger.Panic("unable to start DHT service", "error", err)
return nil
}

Expand All @@ -51,7 +51,7 @@ func (dht *dhtService) Start() error {

func (dht *dhtService) Stop() {
if err := dht.kademlia.Close(); err != nil {
dht.logger.Error("unable to close Kademlia", "err", err)
dht.logger.Error("unable to close Kademlia", "error", err)
}

dht.bootstrap.Stop()
Expand Down
4 changes: 2 additions & 2 deletions network/gossip.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func newGossipService(ctx context.Context, host lp2phost.Host, eventCh chan Even
) *gossipService {
pubsub, err := lp2pps.NewGossipSub(ctx, host)
if err != nil {
logger.Panic("unable to start Gossip service", "err", err)
logger.Panic("unable to start Gossip service", "error", err)
return nil
}

Expand Down Expand Up @@ -66,7 +66,7 @@ func (g *gossipService) JoinTopic(name string) (*lp2pps.Topic, error) {
for {
m, err := sub.Next(g.ctx)
if err != nil {
g.logger.Debug("readLoop error", "err", err)
g.logger.Debug("readLoop error", "error", err)
return
}

Expand Down
4 changes: 2 additions & 2 deletions network/mdns.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (mdns *mdnsService) HandlePeerFound(pi lp2ppeer.AddrInfo) {
if pi.ID != mdns.host.ID() {
mdns.logger.Debug("connecting to new peer", "addr", pi.Addrs, "id", pi.ID.Pretty())
if err := mdns.host.Connect(ctx, pi); err != nil {
mdns.logger.Error("error on connecting to peer", "id", pi.ID.Pretty(), "err", err)
mdns.logger.Error("error on connecting to peer", "id", pi.ID.Pretty(), "error", err)
}
}
}
Expand All @@ -58,6 +58,6 @@ func (mdns *mdnsService) Start() error {
func (mdns *mdnsService) Stop() {
err := mdns.service.Close()
if err != nil {
mdns.logger.Error("unable to close the network", "err", err)
mdns.logger.Error("unable to close the network", "error", err)
}
}
2 changes: 1 addition & 1 deletion network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ func (n *network) Stop() {
n.stream.Stop()

if err := n.host.Close(); err != nil {
n.logger.Error("unable to close the network", "err", err)
n.logger.Error("unable to close the network", "error", err)
}
}

Expand Down
6 changes: 3 additions & 3 deletions network/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (s *streamService) SendRequest(msg []byte, pid lp2peer.ID) error {
stream, err := s.host.NewStream(
lp2pnetwork.WithNoDial(s.ctx, "should already have connection"), pid, s.protocolID)
if err != nil {
s.logger.Debug("unable to open direct stream", "pid", pid, "err", err)
s.logger.Debug("unable to open direct stream", "pid", pid, "error", err)
if len(s.relayAddrs) == 0 {
return err
}
Expand Down Expand Up @@ -100,7 +100,7 @@ func (s *streamService) SendRequest(msg []byte, pid lp2peer.ID) error {

if err := s.host.Connect(s.ctx, unreachableRelayInfo); err != nil {
// There is no relay connection to peer as well
s.logger.Warn("unable to connect to peer using relay", "pid", pid, "err", err)
s.logger.Warn("unable to connect to peer using relay", "pid", pid, "error", err)
return LibP2PError{Err: err}
}
s.logger.Debug("connected to peer using relay", "pid", pid)
Expand All @@ -110,7 +110,7 @@ func (s *streamService) SendRequest(msg []byte, pid lp2peer.ID) error {
stream, err = s.host.NewStream(
lp2pnetwork.WithUseTransient(s.ctx, string(s.protocolID)), pid, s.protocolID)
if err != nil {
s.logger.Warn("unable to open relay stream", "pid", pid, "err", err)
s.logger.Warn("unable to open relay stream", "pid", pid, "error", err)
return LibP2PError{Err: err}
}
}
Expand Down
20 changes: 10 additions & 10 deletions state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ func (st *state) UpdateLastCertificate(cert *certificate.Certificate) error {
// Check if certificate has more signers ...
if len(cert.Absentees()) < len(st.lastInfo.Certificate().Absentees()) {
if err := st.validatePrevCertificate(cert, st.lastInfo.BlockHash()); err != nil {
st.logger.Warn("try to update last certificate, but it's invalid", "err", err)
st.logger.Warn("try to update last certificate, but it's invalid", "error", err)
return err
}
st.lastInfo.UpdateCertificate(cert)
Expand Down Expand Up @@ -317,7 +317,7 @@ func (st *state) ProposeBlock(signer crypto.Signer, rewardAddr crypto.Address, r
}

if err := exe.Execute(txs[i], sb); err != nil {
st.logger.Debug("found invalid transaction", "tx", txs[i], "err", err)
st.logger.Debug("found invalid transaction", "tx", txs[i], "error", err)
txs.Remove(i)
i--
}
Expand Down Expand Up @@ -440,7 +440,7 @@ func (st *state) CommitBlock(height uint32, block *block.Block, cert *certificat
}

if err := st.store.WriteBatch(); err != nil {
st.logger.Panic("unable to update state", "err", err)
st.logger.Panic("unable to update state", "error", err)
}

st.logger.Info("new block committed", "block", block, "round", cert.Round())
Expand Down Expand Up @@ -490,7 +490,7 @@ func (st *state) evaluateSortition() bool {
evaluated = true
} else {
st.logger.Error("our sortition transaction is invalid!",
"address", signer.Address(), "power", val.Power(), "tx", trx, "err", err)
"address", signer.Address(), "power", val.Power(), "tx", trx, "error", err)
}
}
}
Expand Down Expand Up @@ -630,7 +630,7 @@ func (st *state) MakeCommittedBlock(data []byte, height uint32, blockHash hash.H
func (st *state) CommittedBlock(height uint32) *store.CommittedBlock {
b, err := st.store.Block(height)
if err != nil {
st.logger.Trace("error on retrieving block", "err", err)
st.logger.Trace("error on retrieving block", "error", err)
return nil
}
return b
Expand All @@ -639,7 +639,7 @@ func (st *state) CommittedBlock(height uint32) *store.CommittedBlock {
func (st *state) CommittedTx(id tx.ID) *store.CommittedTx {
tx, err := st.store.Transaction(id)
if err != nil {
st.logger.Trace("searching transaction in local store failed", "id", id, "err", err)
st.logger.Trace("searching transaction in local store failed", "id", id, "error", err)
}
return tx
}
Expand All @@ -655,15 +655,15 @@ func (st *state) BlockHeight(hash hash.Hash) uint32 {
func (st *state) AccountByAddress(addr crypto.Address) *account.Account {
acc, err := st.store.Account(addr)
if err != nil {
st.logger.Trace("error on retrieving account", "err", err)
st.logger.Trace("error on retrieving account", "error", err)
}
return acc
}

func (st *state) AccountByNumber(number int32) *account.Account {
acc, err := st.store.AccountByNumber(number)
if err != nil {
st.logger.Trace("error on retrieving account", "err", err)
st.logger.Trace("error on retrieving account", "error", err)
}
return acc
}
Expand All @@ -675,7 +675,7 @@ func (st *state) ValidatorAddresses() []crypto.Address {
func (st *state) ValidatorByAddress(addr crypto.Address) *validator.Validator {
val, err := st.store.Validator(addr)
if err != nil {
st.logger.Trace("error on retrieving validator", "err", err)
st.logger.Trace("error on retrieving validator", "error", err)
}
return val
}
Expand All @@ -684,7 +684,7 @@ func (st *state) ValidatorByAddress(addr crypto.Address) *validator.Validator {
func (st *state) ValidatorByNumber(n int32) *validator.Validator {
val, err := st.store.ValidatorByNumber(n)
if err != nil {
st.logger.Trace("error on retrieving validator", "err", err)
st.logger.Trace("error on retrieving validator", "error", err)
}
return val
}
Expand Down
4 changes: 2 additions & 2 deletions store/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func newAccountStore(db *leveldb.DB) *accountStore {

acc, err := account.FromBytes(value)
if err != nil {
logger.Panic("unable to decode account", "err", err)
logger.Panic("unable to decode account", "error", err)
}

var addr crypto.Address
Expand Down Expand Up @@ -87,7 +87,7 @@ func (as *accountStore) iterateAccounts(consumer func(crypto.Address, *account.A
func (as *accountStore) updateAccount(batch *leveldb.Batch, addr crypto.Address, acc *account.Account) {
data, err := acc.Bytes()
if err != nil {
logger.Panic("unable to encode account", "err", err)
logger.Panic("unable to encode account", "error", err)
}
if !as.hasAccount(addr) {
as.total++
Expand Down
2 changes: 1 addition & 1 deletion store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func tryGet(db *leveldb.DB, key []byte) ([]byte, error) {
data, err := db.Get(key, nil)
if err != nil {
// Probably key doesn't exist in database
logger.Trace("database error", "err", err, "key", key)
logger.Trace("database error", "error", err, "key", key)
return nil, err
}
return data, nil
Expand Down
4 changes: 2 additions & 2 deletions store/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func newValidatorStore(db *leveldb.DB) *validatorStore {

val, err := validator.FromBytes(value)
if err != nil {
logger.Panic("unable to decode validator", "err", err)
logger.Panic("unable to decode validator", "error", err)
}

numberMap[val.Number()] = val
Expand Down Expand Up @@ -92,7 +92,7 @@ func (vs *validatorStore) iterateValidators(consumer func(*validator.Validator)
func (vs *validatorStore) updateValidator(batch *leveldb.Batch, val *validator.Validator) {
data, err := val.Bytes()
if err != nil {
logger.Panic("unable to encode validator", "err", err)
logger.Panic("unable to encode validator", "error", err)
}
if !vs.hasValidator(val.Address()) {
vs.total++
Expand Down
4 changes: 2 additions & 2 deletions sync/firewall/firewall.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (f *Firewall) OpenGossipBundle(data []byte, source peer.ID, from peer.ID) *

bdl, err := f.openBundle(bytes.NewReader(data), source)
if err != nil {
f.logger.Warn("firewall: unable to open a gossip bundle", "err", err)
f.logger.Warn("firewall: unable to open a gossip bundle", "error", err)
f.closeConnection(from)
return nil
}
Expand All @@ -62,7 +62,7 @@ func (f *Firewall) OpenGossipBundle(data []byte, source peer.ID, from peer.ID) *
func (f *Firewall) OpenStreamBundle(r io.Reader, from peer.ID) *bundle.Bundle {
bdl, err := f.openBundle(r, from)
if err != nil {
f.logger.Warn("firewall: unable to open a stream bundle", "err", err)
f.logger.Warn("firewall: unable to open a stream bundle", "error", err)
f.closeConnection(from)
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion sync/handler_transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func (handler *transactionsHandler) ParseMessage(m message.Message, _ peer.ID) e

for _, trx := range msg.Transactions {
if err := handler.state.AddPendingTx(trx); err != nil {
handler.logger.Debug("cannot append transaction", "tx", trx, "err", err)
handler.logger.Debug("cannot append transaction", "tx", trx, "error", err)

// TODO: set peer as bad peer?
}
Expand Down
Loading

0 comments on commit 673e5cc

Please sign in to comment.