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

Simplify static fee calculations #3240

Merged
merged 12 commits into from
Jul 30, 2024

Conversation

StephenButtolph
Copy link
Contributor

@StephenButtolph StephenButtolph commented Jul 27, 2024

Why this should be merged

The main goal of this PR is to simplify the fee.NewStaticCalculator signature. Previously the signature was:

func NewStaticCalculator(
	config StaticConfig,
	upgradeTimes upgrade.Config,
	chainTime time.Time,
) Calculator

Now it is:

func NewStaticCalculator(config StaticConfig) Calculator

How this works

This is done by removing CreateAssetFee from the StaticConfig and expecting CreateSubnetTxFee and CreateBlockchainTxFee to be set by the caller.

How this was tested

  • CI
  • Bootstrapped P-chain


func (c *staticVisitor) RewardValidatorTx(*txs.RewardValidatorTx) error {
c.fee = 0 // no fees
c.fee = c.config.CreateSubnetTxFee
return nil
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These are replaced with more explicit errors rather than returning no fees.

AddSubnetDelegatorFee uint64
NetworkID uint32
AVAXAssetID ids.ID
StaticFeeConfig fee.StaticConfig
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now that the config doesn't have the CreateAssetFee - we can just use the config here directly 🥳

chainTime time.Time
unsignedTx func() txs.UnsignedTx
expected uint64
txTests = []struct {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These tests will be re-used for the dynamic fees tests.

Comment on lines +83 to 92
// NewStaticFeeCalculator creates a static fee calculator, with the config set
// to either the pre-AP3 or post-AP3 config.
func NewStaticFeeCalculator(cfg *config.Config, timestamp time.Time) fee.Calculator {
config := cfg.StaticFeeConfig
if !cfg.UpgradeConfig.IsApricotPhase3Activated(timestamp) {
config.CreateSubnetTxFee = cfg.CreateAssetTxFee
config.CreateBlockchainTxFee = cfg.CreateAssetTxFee
}
return fee.NewStaticCalculator(config)
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not convinced that this is the right place for these methods... But will leave that decision to a later PR.

@StephenButtolph StephenButtolph self-assigned this Jul 28, 2024
@StephenButtolph StephenButtolph added cleanup Code quality improvement acp103 labels Jul 28, 2024
@StephenButtolph StephenButtolph added this to the v1.11.11 milestone Jul 28, 2024
@StephenButtolph StephenButtolph marked this pull request as ready for review July 28, 2024 00:18
Copy link
Contributor

@abi87 abi87 left a comment

Choose a reason for hiding this comment

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

lgtm

unsignedTx: createChainTx,
expected: feeTestsDefaultCfg.CreateAssetTxFee,
name: "RewardValidatorTx",
tx: "0000000000143d0ad12b8ee8928edf248ca91ca55600fb383f07c32bff1d6dec472b25cf59a700000000",
Copy link
Contributor

Choose a reason for hiding this comment

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

(No action required) Maybe prefer using a non-opaque format for this kind of test data to simplify review and maintenance? Or is there a reason that tx decoding and parsing shouldn't be orthogonal to fee calculation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you think it would be better to move these transactions to separate files (and embed them?). These are really more intended to be compliance tests that should never change... I feel like if we included them in their non-binary forms... Their definition would dominate the tests... When really I think of them as amorphous tests to prevent unexpected changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added a TODO for this. I spent like 3 hours yesterday trying to come up with a nice way to implement this and I didn't make progress towards something I liked.

I don't want to block the rest of the PRs on this test definition.

@StephenButtolph StephenButtolph added this pull request to the merge queue Jul 30, 2024
Merged via the queue into master with commit 809081e Jul 30, 2024
20 checks passed
@StephenButtolph StephenButtolph deleted the simplify-static-fee-calculations branch July 30, 2024 16:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
acp103 cleanup Code quality improvement
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

4 participants