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

swap: message price #1827

Merged
merged 21 commits into from
Oct 2, 2019
Merged

swap: message price #1827

merged 21 commits into from
Oct 2, 2019

Conversation

Eknir
Copy link
Contributor

@Eknir Eknir commented Sep 27, 2019

This PR is desirable to run the Devcon workshop in Osaka. Without it, participants won't be able to see their balance of Ether increase as a consequence of SWAP: they are paying more in tx costs than they receive from cashing.

  • Sets a more realistic message price for chunkDelivery / chunkRequest
  • Updates the payment threshold to send payment when a peer has a balance equivalent of 10 mb of data
  • Updates the disconnect threshold to be 20 times the payment threshold.
  • Implements a very basic cash-out strategy of cashing out when you earn 2 times the transaction costs.

swap/prices.go Outdated Show resolved Hide resolved
swap/swap.go Outdated Show resolved Hide resolved
@zelig
Copy link
Member

zelig commented Sep 30, 2019

@zelig zelig added this to Backlog in Swarm Core - Sprint planning via automation Sep 30, 2019
@zelig zelig added this to the 0.5.1 milestone Sep 30, 2019
swap/swap.go Outdated
// cash cheque in async, otherwise this blocks here until the TX is mined
go defaultCashCheque(s, otherSwap, opts, cheque)
gasPrice, err := s.backend.SuggestGasPrice(context.TODO())
transactionCosts := gasPrice.Uint64() * 50000 // cashing a cheque is approximately 50000 gas
Copy link
Contributor Author

Choose a reason for hiding this comment

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

An issue was created to make this non-hardcoded: #1845

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.

This is close to ready to go.

A couple of minor things. I think we should use an average cloud storage price as a base for calculation.
And I prefer we do the type conversion for thresholds only once, instead of at every Add

swap/prices.go Outdated
@@ -33,9 +33,15 @@ allowing for a multi-currency design.
*/

// Placeholder prices
// Based on a very crude calculation: average monthly cost for bandwidth in the US / average monthly bill for bandwidth in the US
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should use an average cloud storage price instead of internet provider cost

Copy link
Contributor Author

@Eknir Eknir Oct 2, 2019

Choose a reason for hiding this comment

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

Based on the conversation in the chat, I leave it as-is. This is not because I don't think you are right, but because I think that both presented options have flaws which we must consider. Changing it now to a different price will possibly bring up other issues and for the workshop the chosen price is sufficient.

How would you go about defining this in a more proper manner? In my opinion, we must first agree on a methodology on how to get the price, after which we can apply this methodology. Shall we plan a workshop in Japan with the incentives team and research?

swap/prices.go Outdated
// 0.35 / (10^9 * 4096) = $0.0000014336 / chunk
// 0.0000014336 / 166 * 10^18 = 8636144578.31 Wei / chunk, where 166 is the current Ether price in Dollar
// RetrieveRequestPrice = 0.1 * 8636144578.31 = 863614458
// ChunkDeliveryPrice = 0.9 * 8636144578.31 = 7772530120
Copy link
Contributor

Choose a reason for hiding this comment

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

Just clarify that those factors are currently bogus

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

// cashCheque cashes a cheque when we get twice the transaction costs.
// gasPrice on testBackend == 1
// estimated gas costs == 50000
// cheque should be send if the accumulated uncashed cheques is worth more than 100000
Copy link
Contributor

Choose a reason for hiding this comment

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

cheque should be sent (typo)

Copy link
Contributor

Choose a reason for hiding this comment

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

also are worth instead of is worth

Copy link
Contributor Author

@Eknir Eknir Oct 2, 2019

Choose a reason for hiding this comment

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

cheques should be sent updated
are worth not updated, as the accumulated amount is worth and not accumulated amount are worth. Added amount, to make this clear.

swap/swap.go Outdated
@@ -76,8 +76,8 @@ type Owner struct {
// Params encapsulates param
type Params struct {
LogPath string // optional audit log path
PaymentThreshold int64 // honey amount at which a payment is triggered
DisconnectThreshold int64 // honey amount at which a peer disconnects
PaymentThreshold uint64 // honey amount at which a payment is triggered
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't agree to changing the data type here.

While I understand why you want to do it, the way you propose now has the consequence that now on every comparison we need to do a conversion, while as it was before (if I interpret correctly) the conversion is only done once, when we set these thresholds in the params.

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 back. Fully agree with your reasoning, thanks

swap/swap.go Outdated
@@ -251,7 +251,7 @@ func (s *Swap) Add(amount int64, peer *protocols.Peer) (err error) {

// Check if balance with peer is over the disconnect threshold
balance := swapPeer.getBalance()
if balance >= s.params.DisconnectThreshold {
if balance >= int64(s.params.DisconnectThreshold) {
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 what I mean, now we have to do the conversion on every Add, which is unnecessary, especially because it's always the same value.

swap/swap.go Outdated
@@ -262,7 +262,7 @@ func (s *Swap) Add(amount int64, peer *protocols.Peer) (err error) {
// Check if balance with peer crosses the payment threshold
// It is the peer with a negative balance who sends a cheque, thus we check
// that the balance is *below* the threshold
if swapPeer.getBalance() <= -s.params.PaymentThreshold {
if swapPeer.getBalance() <= -int64(s.params.PaymentThreshold) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here.

swap/swap.go Show resolved Hide resolved
swap/swap.go Show resolved Hide resolved
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 see no major issues, just have a couple of questions

cmd/swarm/config_test.go Show resolved Hide resolved
swap/config.go Outdated Show resolved Hide resolved
// cashCheque cashes a cheque when we get twice the transaction costs.
// gasPrice on testBackend == 1
// estimated gas costs == 50000
// cheque should be send if the accumulated uncashed cheques is worth more than 100000
Copy link
Contributor

Choose a reason for hiding this comment

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

also are worth instead of is worth

swap/protocol_test.go Outdated 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.

There are some minor things @holisticode pointed out about error handling, that should be addressed before merging.
The change of int64 to uint64 is justified but is a bit verbose now, but it's ok.

The discussion of prices, in my opinion, should be resolved may be in a different PR, because this more about solving this issue for the workshop rather than a definite solution.

Other than that LGTM.

@santicomp2014
Copy link
Contributor

The linter is complaining of unnecessary conversion, because of the switch back to int64.

swap/swap_test.go:779:25: unnecessary conversion (unconvert)
		if peerBalance < int64(swap.params.DisconnectThreshold) {

@mortelli
Copy link
Contributor

mortelli commented Oct 2, 2019

master has new commits, please rebase/merge

@holisticode holisticode merged commit fa28dad into master Oct 2, 2019
Swarm Core - Sprint planning automation moved this from Backlog to Done Oct 2, 2019
@mortelli mortelli deleted the incentives-message_price branch November 14, 2019 18:53
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

6 participants