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

cmd/swarm, swarm, swap, api: configurable payment/disconnect thresholds #1729

Merged
merged 45 commits into from
Sep 18, 2019

Conversation

Eknir
Copy link
Contributor

@Eknir Eknir commented Sep 5, 2019

  • Allow for configuration of disconnect and payment threshold
  • Make Swap flags override the config
  • Tests for the working of the disconnect/payment threshold
  • Move swap-related logic from swarm.go:NewSwarm to swap/swap.go:New
  • After merge: update documentation

closes #1441

@Eknir Eknir changed the title Incentives threshold config cmd/swarm, swarm, swap, api: configurable payment/disconnect thresholds Sep 5, 2019
Copy link
Contributor

@mortelli mortelli left a comment

Choose a reason for hiding this comment

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

i know that this PR is a draft still, but while i had some time to review it i though i might as well. so please consider this review as preliminary 😃

my comments are mainly coding style-related, but i do have an important question:

are we adding a disconnect oracle as well as a payment one?

api/config.go Outdated Show resolved Hide resolved
api/config.go Outdated Show resolved Hide resolved
cmd/swarm/config.go Outdated Show resolved Hide resolved
cmd/swarm/config.go Show resolved Hide resolved
cmd/swarm/main.go Show resolved Hide resolved
swap/config.go Outdated Show resolved Hide resolved
swap/swap.go Outdated Show resolved Hide resolved
swap/swap.go Outdated Show resolved Hide resolved
swap/swap.go Outdated Show resolved Hide resolved
swarm_test.go Outdated Show resolved Hide resolved
@Eknir Eknir marked this pull request as ready for review September 10, 2019 11:15
Copy link
Member

@zelig zelig left a comment

Choose a reason for hiding this comment

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

minor things

api/config.go Outdated
@@ -52,12 +53,14 @@ type Config struct {
BaseKey []byte

// Swap configs
SwapBackendURL string
SwapEnabled bool
SwapBackendURL string
Copy link
Member

Choose a reason for hiding this comment

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

more explanation in comment needed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What do you mean here?

Copy link
Member

Choose a reason for hiding this comment

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

please comment exported constants, explain what they are

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

swap/swap.go Outdated
@@ -350,7 +352,7 @@ func (s *Swap) sendCheque(swapPeer *Peer) error {

log.Info("sending cheque", "honey", cheque.Honey, "cumulativePayout", cheque.ChequeParams.CumulativePayout, "beneficiary", cheque.Beneficiary, "contract", cheque.Contract)
s.setCheque(peer, cheque)

fmt.Println(sentChequeKey(peer))
Copy link
Member

Choose a reason for hiding this comment

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

oops

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed

@@ -289,6 +292,32 @@ func TestRepeatedBookings(t *testing.T) {
verifyBookings(t, swap, append(bookings, mixedBookings...))
}

func TestDisconnectThreshold(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

give description of tests in a comment

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

swarm_test.go Outdated
@@ -114,7 +112,7 @@ func TestNewSwarm(t *testing.T) {
configure: func(config *api.Config) {
config.SwapBackendURL = ipcEndpoint
config.SwapEnabled = true
config.NetworkID = swap.AllowedNetworkID
config.NetworkID = 2
Copy link
Member

Choose a reason for hiding this comment

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

better use constant still, so that the name gives away why we expect that value to behave the way we want

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed

Copy link
Contributor

@holisticode holisticode left a comment

Choose a reason for hiding this comment

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

Coming close, mostly minor issues left but a couple are important.

swap/swap.go Outdated Show resolved Hide resolved
cmd/swarm/config.go Show resolved Hide resolved
cmd/swarm/config_test.go Outdated Show resolved Hide resolved
cmd/swarm/config_test.go Outdated Show resolved Hide resolved
@@ -65,6 +65,16 @@ var (
Usage: "URL of the Ethereum API provider to use to settle SWAP payments",
EnvVar: SwarmEnvSwapBackendURL,
}
SwarmSwapPaymentThresholdFlag = cli.Uint64Flag{
Name: "swap-payment-threshold",
Usage: "honey amount indebted to a peer at which you will initiate payment",
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 only from one peer's point of view. I would change this to "honey amount at which a payment is triggered"

Copy link
Contributor Author

@Eknir Eknir Sep 16, 2019

Choose a reason for hiding this comment

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

I think in anything outside of the test directory, we should make the comments and variable names as if it is from the perspective of the node operator. Especially here, as this is a user-facing comment.

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe, but even then, this node operator can cross the payment threshold in both ways. The threshold doesn't define if you are indebted or not, which is defined only in which direction you cross it.

I would like to insist on this being changed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, this threshold does define whether a node is indebted or not, because the threshold which is set here only applies to what this particular node does. Sure, there are other payment thresholds in the network, and the node can cross these from the other direction (and get paid). but this particular threshold is only about how much the node that the user is about to boot up must be indebted to other peers until payment will be initiated.

Copy link
Contributor

Choose a reason for hiding this comment

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

What if we would add a log Warn on the creditor node that a peer crossed the threshold and is indebted with him?

Check this exact comment I made on another PR: #1754 (comment)

If we did this (and if we add some other metric or anything to help nodes track that peers got indebted to them), then your comment would not apply.

swap/swap_test.go Outdated Show resolved Hide resolved
swap/swap_test.go Outdated Show resolved Hide resolved
swarm.go Outdated Show resolved Hide resolved
swarm.go Show resolved Hide resolved
swarm_test.go Outdated Show resolved Hide resolved
@zelig
Copy link
Member

zelig commented Sep 16, 2019

@Eknir @holisticode what is the status of this PR?

Copy link
Contributor

@mortelli mortelli left a comment

Choose a reason for hiding this comment

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

let's resolve the open threads from @holisticode's review

@mortelli mortelli dismissed their stale review September 16, 2019 13:35

changes were applied, but PR is not ready to be approved yet

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.

LGTM

Copy link
Contributor

@holisticode holisticode left a comment

Choose a reason for hiding this comment

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

Just last couple of things please and then we are good.

Copy link
Contributor

@holisticode holisticode left a comment

Choose a reason for hiding this comment

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

Approved but check #1729 (comment)

@Eknir Eknir merged commit 11c05dc into master Sep 18, 2019
chadsr added a commit to chadsr/swarm that referenced this pull request Sep 23, 2019
* 'master' of github.com:ethersphere/swarm: (32 commits)
  network/stream: refactor cursors tests (ethersphere#1786)
  network: Add capabilities if peer from store does not have it (ethersphere#1791)
  Swap logger (ethersphere#1754)
  network: Add capability filtered depth calculation (ethersphere#1787)
  travis: remove go1.12 job (ethersphere#1784)
  cmd/swarm: correct bzznetworkid flag description (ethersphere#1761)
  network, pss: Capability in pss (ethersphere#1764)
  network/stream: handle nil peer in TestNodesExchangeCorrectBinIndexes (ethersphere#1779)
  protocols, retrieval: swap-enabled messages implement Price (ethersphere#1771)
  cmd/swarm-smoke: fix waitToPushSynced connection closing (ethersphere#1781)
  cmd/swarm: simplify testCluster.StartNewNodes (ethersphere#1777)
  build: increase golangci-lint deadline (ethersphere#1778)
  docker: ignore build/bin when copying files (ethersphere#1780)
  swap: fix and rename Peer.getLastSentCumulativePayout (ethersphere#1769)
  network/stream: more resilient TestNodesCorrectBinsDynamic (ethersphere#1776)
  network: Add Capabilities to Kademlia database (ethersphere#1713)
  network: add own address to KademliaInfo (ethersphere#1775)
  pss: Refactor. Step 2. Refactor forward cache (ethersphere#1742)
  all: configurable payment/disconnect thresholds (ethersphere#1729)
  network/stream/v2: more resilient TestNodesExchangeCorrectBinIndexes (ethersphere#1760)
  ...
@mortelli mortelli deleted the incentives-thresholdConfig branch November 14, 2019 18:57
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.

Allow parametrization of thresholds
6 participants