-
Notifications
You must be signed in to change notification settings - Fork 112
Conversation
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 |
There was a problem hiding this comment.
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
There was a problem hiding this 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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
swap/protocol_test.go
Outdated
// 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 |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here.
There was a problem hiding this 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
swap/protocol_test.go
Outdated
// 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 |
There was a problem hiding this comment.
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
There was a problem hiding this 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.
The linter is complaining of unnecessary conversion, because of the switch back to int64.
|
|
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.