Skip to content
This repository has been archived by the owner on Aug 2, 2021. It is now read-only.

swarm, swap: add addresses to logs #1806

Merged
merged 40 commits into from
Oct 14, 2019
Merged

swarm, swap: add addresses to logs #1806

merged 40 commits into from
Oct 14, 2019

Conversation

mortelli
Copy link
Contributor

@mortelli mortelli commented Sep 24, 2019

This PR aims to resolve #1623, which is about adding node and peer addresses to SWAP log entries in order to be able to debug more easily (this includes simulations).

Changes:

  • as in other protocols (such as bzzeth) the swap Peer struct now has its own logger; using a context specific to each peer, we can log each id automatically this way.
  • a regular SWAP logger (not specific to any peer) is kept as a package variable; not all SWAP log entries are related to peers.
    • there is now a specific function to create each of these logger types.
  • small fixes to SWAP tests.
  • piggyback renaming of the new function (swap/swap.go:134) to newSwapInstance.

Notes:

  • I am assuming there's not an issue with the file handlers accessing the same log file from different threads (I might be wrong, but I believe this was still applicable before this PR).
  • this branch takes PR Swap logger #1754 as a starting point.
  • if merged, this PR should be taken as a starting point for Refactor swap logs with actions prefix #1788.

swap/peer.go Show resolved Hide resolved
Copy link
Contributor

@santicomp2014 santicomp2014 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job refactoring the logger.
I left a few comments regarding logpath and other minor things.

Other than that it LGTM

swap/swap.go Outdated Show resolved Hide resolved
swap/swap.go Outdated Show resolved Hide resolved
swap/swap.go Outdated Show resolved Hide resolved
# Conflicts:
#	swap/swap.go
#	swap/swap_test.go
Copy link
Member

@acud acud left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor stuff and definitely not a blocker.
also - please rebase master

swap/swap.go Outdated Show resolved Hide resolved
swap/swap.go Outdated
_, err := s.processAndVerifyCheque(cheque, p)
if err != nil {
return err
}

auditLog.Debug("received cheque processed and verified", "peer", p.ID().String())
p.logger.Debug("received cheque, processed and verified")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wouldn't it be good to log which cheque was processed and verified? without any identifying details this logline doesn't say much

Copy link
Contributor Author

@mortelli mortelli Sep 30, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could add honey as in line 307, but other than that, i'm not sure which field could identify a cheque in a way that is useful for logs.

i am certain that knowing a cheque has arrived/been sent is useful already.

tagging @ralph-pichler and @Eknir for insight

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CumulativePayout and Contract fields should be enough to uniquely identify which cheque it is. Instead of Contract p.beneficiary might also be useful (this would be the signer of the cheque here).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added Beneficiary and CumulativePayout to this Debug log entry

thanks guys

# Conflicts:
#	swap/swap.go
#	swap/swap_test.go
#	swarm.go
Copy link
Contributor

@santicomp2014 santicomp2014 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I closed my discussion on package wide variables.
The implementation is correct, good job.
LGTM.

swap/peer.go Show resolved Hide resolved
swap/swap_test.go Show resolved Hide resolved
swap/swap.go Outdated
@@ -118,14 +131,15 @@ func swapRotatingFileHandler(logdir string) (log.Handler, error) {
}

// new - swap constructor without integrity check
func new(stateStore state.Store, owner *Owner, backend contract.Backend, params *Params) *Swap {
func new(stateStore state.Store, owner *Owner, backend contract.Backend, params *Params, logger log.Logger) *Swap {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not from this PR, but we need to rename this function, it creates a conflict with the builtin new keyword of go if it would be used inside this package.

Call it newInstance or something else you prefer. You can also create a different PR for this if you prefer.

Copy link
Contributor Author

@mortelli mortelli Oct 7, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pushed this change and added it to the PR description. thanks

swap/swap.go Outdated
@@ -63,6 +62,7 @@ type Swap struct {
params *Params // economic and operational parameters
contract swap.Contract // reference to the smart contract
honeyPriceOracle HoneyOracle // oracle which resolves the price of honey (in Wei)
logger log.Logger // logger for swap related messages and audit trail
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we not keep the swapLogger package wide and only do the peerLogger per instance?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think we can, but i'm not sure i see reason to.

could you please explain why this would be preferable? in general i try to avoid global variables and the like.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the logger is shared, and is not in any way a property of Swap. Then we also don't need to pass it around methods.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's a logger specifically for swap, but yes, maybe it doesn't belong in the struct itself (although if the logpath does, one could argue for this).

it certainly doesn't need to be there.

i've changed it back to a global variable.

type Params struct {
OverlayAddr []byte // this node's base address
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be honest Params is poorly designed and was meant as an organizing thing for economic parametrization (thresholds, cashing strategy, amounts, etc.).

We have been refactoring the Swap constructor all the time recently, that is why instead of making a huuuuuge constructor with maaaany parameters (resulting in many changes), we started adding mixed parameters to this generic Params struct.

I would like to see a refactoring of this, but it does not need to be in this PR. Conceptually OverlayAddr does not belong to this struct, but LogPath neither does.

Copy link
Contributor Author

@mortelli mortelli Oct 10, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i agree.

i never really understood this Params business—indeed, i only placed OverlayAddr here since it seemed to fit in well next to logpath as an "infrastructure" sort of variable for the Swap struct 🤷‍♂️

we can have them moved to the Swap struct directly if you prefer, i don't mind.

or: we can revisit this issue later down the road, when refactoring as you say

Copy link
Contributor Author

@mortelli mortelli Oct 14, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

created issue #1877 for this

@mortelli mortelli merged commit 2027aae into master Oct 14, 2019
@mortelli mortelli deleted the swap-logger-addresses branch October 14, 2019 14:28
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

expand SWAP logs to include self address
6 participants