Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add RequiredFee field to Check/DeliverResult #357

Merged
merged 11 commits into from
Feb 27, 2019
Merged

Conversation

ethanfrey
Copy link
Contributor

@ethanfrey ethanfrey commented Feb 26, 2019

Addresses #349

This just adds the fields, must be rebased once #348 is closed and then enforce the required fee in the DynamicFeeHandler.

First pass, to add x.Coin to the weave.DeliverResult creates an import cycle. weave -> x -> weave

This repo was designed that modules only import from their parent modules to avoid cycles, and that we use interfaces defined in the top level rather than reference implementations from sibling modules. There are two main exceptions, errors and crypto, which are generic libraries and can be imported by any package, in addition to weave itself.

Anyway, if we now add Coin to a project-wide interface, I see three options:

  • Move coin and coins and related code from x to weave and update all imports
  • Make a new packages coins with coin.go, coins.go etc and treat that as a library package like crypto and errors
  • Totally rethink how we handle imports

Conclusion I put everything in the coin package and changed tons of imports...

@ethanfrey ethanfrey added the WIP label Feb 26, 2019
@ethanfrey ethanfrey requested a review from alpe as a code owner February 26, 2019 16:35
@ruseinov
Copy link
Contributor

@ethanfrey in my opinion best way to resolve it is to implement getter methods for whatever is needed and pass an interface to deliver instead of x.Coin directly.

Then the deliver result won't care about the actual type and we can still get the juice.

And yeah, in concrete decorator we can cast the type.

@ethanfrey
Copy link
Contributor Author

The point is we need to get and set this in many places....

And I can't even define

type interface Getter {
  GetFee() x.Coin
}

due to the imports... I really want to set a coin on it, but it currently cannot know what a coin is...

pulling out coins in a PR now

@ruseinov
Copy link
Contributor

I mean, why can't this be an interface{} or a type that implements some methods, like GetWhole() GetFractional() GetTicker() and then you can cast it in some other places you need to.

could be a Currency interface or something

@ethanfrey ethanfrey mentioned this pull request Feb 26, 2019
@ethanfrey ethanfrey self-assigned this Feb 26, 2019
@codecov-io
Copy link

codecov-io commented Feb 26, 2019

Codecov Report

Merging #357 into master will increase coverage by <.1%.
The diff coverage is 81.9%.

Impacted file tree graph

@@           Coverage Diff            @@
##           master    #357     +/-   ##
========================================
+ Coverage    70.3%   70.4%   +<.1%     
========================================
  Files         127     127             
  Lines        6536    6554     +18     
========================================
+ Hits         4600    4616     +16     
- Misses       1462    1463      +1     
- Partials      474     475      +1
Impacted Files Coverage Δ
abci.go 80% <ø> (ø) ⬆️
coin/coins.go 84.8% <ø> (ø)
coin/coin.go 94.5% <ø> (ø)
cmd/bcpd/app/examples.go 0% <0%> (ø) ⬆️
x/currency/msg.go 25% <0%> (ø) ⬆️
cmd/bcpd/app/init.go 82.4% <0%> (ø) ⬆️
cmd/bnsd/app/init.go 76.7% <0%> (ø) ⬆️
cmd/bnsd/app/examples.go 0% <0%> (ø) ⬆️
examples/mycoind/app/examples.go 0% <0%> (ø) ⬆️
x/paychan/handler.go 63.7% <100%> (ø) ⬆️
... and 19 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 515b07f...06fd274. Read the comment docs.

@ethanfrey ethanfrey removed the WIP label Feb 27, 2019
@ethanfrey ethanfrey requested a review from husio February 27, 2019 11:40
@husio
Copy link
Contributor

husio commented Feb 27, 2019

Now that the package for holding coins is called coin, structure names Coin and Coins could be renamed as well. When used it is now func x(amount coin.Coin) or func x(amount coin.Coins). The repetetivnes is weird. This is not an important change but the right renaming could make it look nicer 💅

I cannot propose anything better although my thinking goes in the direction of something like

func x(amount coin.Coin) {} // now, a single ticker value
func x(amount coin.Single) {} // after renaming

func x(amount coin.Coins) {} // now, multiple ticker values
func x(amount coin.Multiple) {} // after renaming

Now that the package is called coin I would love most of methods to be functions. Making all Sum, Sub, Mul, Div, etc. functions that take argumens of any type. It would be awesome if they could work for Coin and Coins. I wonder if this is possible. If yes, the API would look beautiful 🍾

total, err := coins.Sum(amount, tax, fee)

abci.go Outdated
// Log is human-readable informational string
Log string
// RequiredFee can set an custom fee that must be paid for this transaction to be allowed to run.
// This is enforced in cash.DynamicFeeDecorator
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 changing the phrasing from this is enforced to this might be enforced by for example might explain better. Although today this field is added specifically for the use by the cash.DynamicFeeDecorator, anyone should be able to use it. Otherwise it sounds like this is a hard dependency. 💅

I love the comments though. They explain a lot! 🏅

abci.go Outdated
// Log is human-readable informational string
Log string
// RequiredFee can set an custom fee that must be paid for this transaction to be allowed to run.
// This is enforced in cash.DynamicFeeDecorator
Copy link
Contributor

Choose a reason for hiding this comment

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

@ethanfrey
Copy link
Contributor Author

I will update docs. And yes, let's make a new issue for coin package cleanup.

I just pulled it out into a package to compile properly. Would like more input before renaming everything.

@ethanfrey
Copy link
Contributor Author

About renaming, this breaks lots of protobuf definitions.

I would almost prefer to keep Coin and Coins, but the other functions can easily be renamed. And also, the package could have another name easily

@ethanfrey ethanfrey merged commit 0dd8e82 into master Feb 27, 2019
@ethanfrey ethanfrey deleted the required-fee-field branch February 27, 2019 16:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants