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

[WIP] Covenant fees #8

Closed
wants to merge 4 commits into from
Closed

[WIP] Covenant fees #8

wants to merge 4 commits into from

Conversation

rsolari
Copy link

@rsolari rsolari commented Oct 15, 2019

Here's a proof-of-concept of my covenant fees proposal. It's not connected to anything, so it doesn't work yet. My goal is to show the scope of the intended changes and get feedback about them.

There are two parts:

  • The ComposedEstimator class, which keeps track of four estimators, one for each fee limit. Its job is to pass through arguments to the appropriate PolicyEstimator.
  • One interface change in rpc to show the type of changes required changes to fee estimation. This change is just an example. Ultimately, I'd have to change all of the places where something calls estimateFee and estimatePriority.

Does this approach make sense?

@rsolari
Copy link
Author

rsolari commented Oct 15, 2019

TODOs:

  • Add covenantType to 'estimateFee' and 'estimatePriority' more of the calls
  • Hook up the new estimator
  • Add tests
  • Change logger to show which estimator a log line comes from
  • Change comparisons to use types instead of typesByVal. Use types throughout
  • Fix linting
  • Address style nits
  • Move PR to other repo

@tynes
Copy link

tynes commented Oct 15, 2019

Good work! Looking over this, it looks like you are going in the right direction. Definitely some style nits (we try to keep as close to the hsd style as possible) but you can really have whatever style you want if you aren't planning on opening it as a PR against the other hsd repo. I'd also lean towards trying to use the types for comparisons compared to the typesByVal for comparisons.

@rsolari
Copy link
Author

rsolari commented Oct 15, 2019

I plan to merge it into the other repo, so I'll follow hsd style guidelines. Are they written down somewhere? I think I just need to change my editor to grab the write config.

@tynes
Copy link

tynes commented Oct 15, 2019

eslint is used, there should be an .eslintrc in the root of the repo. Since it is a cryptocurrency project, we do not use the normal eslint in case a random dependency is compromised. We instead use chjj/bslint, which commits to specific versions of exactly what we use to lint.

I cloned https://github.com/chjj/bslint and then installed it globally with npm i -g from within the repo. Then its possible to run npm run lint, as eslint is not a dependency of the project. The paranoid will run the linter in a VM or container.

I will leave comments regarding style, I do not think that the linter will catch all of them. Reading through the codebase a few times will help. Things are generally minimal and there is a focus on performance. For example, short variable names, for ... of over map/filter, Buffers where possible.

@0xhaven 0xhaven self-requested a review October 15, 2019 21:29
Copy link

@tynes tynes left a comment

Choose a reason for hiding this comment

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

Please give feedback on the comments. Ultimately, the final decision to merge code doesn't just come down to me but also Zippy and Boyma. These are based on my interpretation of our style so if you disagree, feel free to have them review as well/read through the codebase more to get your own feel for the style.

lib/covenants/rules.js Show resolved Hide resolved
lib/covenants/rules.js Show resolved Hide resolved
lib/mempool/composedFees.js Show resolved Hide resolved
lib/mempool/composedFees.js Show resolved Hide resolved
lib/mempool/composedFees.js Show resolved Hide resolved
lib/node/rpc.js Show resolved Hide resolved
lib/mempool/composedFees.js Show resolved Hide resolved
lib/covenants/rules.js Show resolved Hide resolved
*/
const updateLimitedTypes = new Set(types.OPEN, types.UPDATE, types.TRANSFER, types.REVOKE);

rules.isUpdateLimited = function isUpdateLimited(typeStr) {
Copy link

Choose a reason for hiding this comment

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

I think this should take a Number instead of a string

Copy link

Choose a reason for hiding this comment

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

And we should be very sure that this function doesn't already exist in the codebase someplace

lib/covenants/rules.js Show resolved Hide resolved
@@ -528,6 +528,16 @@ rules.countOpens = function countOpens(tx) {
return total;
};

/**
Copy link

Choose a reason for hiding this comment

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

You could simplify this by making it a bit more abstract and declaring each "Bucket" and either:

  • Storing the bucket in an power-of-two enum and declaring a mapping from each type to its bucket(s)
  • Directly declaring the types included in each bucket and having a single method check for membership in each bucket. (i.e. exporting the "Sets" in a lookup-only wrapper class)

Copy link

Choose a reason for hiding this comment

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

I actually think this bucketing maybe fits best in the fee estimator, not the rules.

* @returns {Rate}
*/

estimateFee(target, smart, covenantType) {
Copy link

Choose a reason for hiding this comment

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

It's not clear that none of these buckets will ever intersect. I think it's simplest just to estimate fees in all applicable ways and take their max at the end.

Copy link
Author

Choose a reason for hiding this comment

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

You mean something like this?

  estimateFee(target, smart, covenantType) {
    const estimates = [];
    if (rules.isOpenLimited(covenantType)) {
      estimates.push(this.openFees.estimateFee(target, smart));
    }
    if (rules.isUpdateLimited(covenantType)) {
      estimates.push(this.updateFees.estimateFee(target, smart));
    }
    if (rules.isRenewalLimited(covenantType)) {
      estimates.push(this.renewalFees.estimateFee(target, smart));
    }

    estimates.push(this.blockspaceFees.estimateFee(target, smart));

    return Math.max(...estimates);
  }

lib/mempool/composedFees.js Show resolved Hide resolved
@tynes
Copy link

tynes commented Oct 16, 2019

You may find this relevant bcoin-org/bcoin#518

@rsolari
Copy link
Author

rsolari commented Oct 17, 2019

Thanks for all your feedback @tynes. I made your suggested changes and reopened the PR against the main repo: handshake-org#282

@rsolari rsolari closed this Oct 17, 2019
@nodech nodech deleted the wip-covenant-fees branch April 20, 2023 07:59
@nodech nodech restored the wip-covenant-fees branch April 20, 2023 07:59
@nodech nodech deleted the wip-covenant-fees branch April 20, 2023 07:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants