Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@neekolas
Copy link
Contributor

@neekolas neekolas commented Sep 2, 2025

TL;DR

Added a fee estimation system to improve fee calculation for message publishing.

What changed?

  • Created a new FeeEstimator that wraps the existing FeeCalculator to provide fee estimates based on recent congestion calculations
  • Added a new IFeeEstimator interface that extends IFeeCalculator with an EstimateFees method
  • Refactored fee calculation logic from publishWorker into a utility function CalculateStagedOriginatorEnvelopeFees
  • Updated the replication server to use the new fee estimation system
  • Added the IFeeCalculator interface to mockery configuration
  • Modified the replication server to require a rates fetcher
  • Added tests for the new fee estimator

How to test?

  1. Run the test suite to verify the new fee estimator functionality:
  2. Start the replication server and verify that message publishing works with the new fee estimation system
  3. Test that fee estimates are properly cached and reused for subsequent message publishing operations

Why make this change?

This change improves the fee calculation system by:

  1. Caching recent congestion fee calculations to provide more accurate fee estimates
  2. Separating the fee calculation logic into reusable utility functions
  3. Making the system more maintainable and testable through proper interface abstractions
  4. Ensuring thread safety for concurrent fee estimation operations

The fee estimator provides a more efficient way to calculate fees by avoiding redundant congestion calculations, which improves performance for high-volume message publishing.

Copy link
Contributor Author

neekolas commented Sep 2, 2025

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • Queue - adds this PR to the back of the merge queue
  • Hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@macroscopeapp
Copy link

macroscopeapp bot commented Sep 2, 2025

Enable fees by requiring a rates fetcher during replication server startup and calculating message publish fees via fees.FeeEstimator

  • Add fees.FeeEstimator implementing IFeeEstimator with congestion-fee caching and EstimateFees in estimator.go and interface in interface.go; tests in estimator_test.go.
  • Require and inject a rates fetcher through server.WithRatesFetcher and ReplicationServerConfig.RatesFetcher, validate in server.NewReplicationServer, and pass into the API in server.go; construct a contract rates fetcher in main.main and supply it to the server in main.go; update test server wiring in server.go.
  • Use fees.CalculateStagedOriginatorEnvelopeFees for publish-time fee computation and reuse a shared queries.Queries in the message publish worker and service in publishWorker.go, service.go, and utils.go.
  • Add generated mock for IFeeCalculator and mockery config in mock_IFeeCalculator.go and .mockery.yaml.

📍Where to Start

Start with server.NewReplicationServer and server.WithRatesFetcher in server.go, then see main.main wiring in main.go, and review fees.FeeEstimator in estimator.go.


Macroscope summarized c69cb89. (Automatic summaries will resume when PR exits draft mode or review begins).

return nil, errors.New("http listener not provided")
}

if cfg.RatesFetcher == nil {
Copy link

Choose a reason for hiding this comment

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

The server fails to initialize without a RatesFetcher even when neither replication nor sync features are enabled, blocking use cases that don't require rates fetching.
This happens because cfg.RatesFetcher is checked unconditionally in NewReplicationServer, but it's only actually needed when cfg.Options.Replication.Enable or cfg.Options.Sync.Enable is true.
Consider only enforcing the RatesFetcher non-nil check when either replication or sync is enabled, so that servers without those features can initialize successfully.

-   if cfg.RatesFetcher == nil {
-       return nil, errors.New("rates fetcher not provided")
-   }
+   if (cfg.Options.Replication.Enable || cfg.Options.Sync.Enable) && cfg.RatesFetcher == nil {
+       return nil, errors.New("rates fetcher not provided")
+   }

🚀 Reply to ask Macroscope to explain or update this suggestion.

👍 Helpful? React to give us feedback.

@neekolas neekolas force-pushed the 08-27-add_fee_estimator_and_enable_fees branch from 59b2f01 to cb08bc4 Compare September 2, 2025 05:51
@neekolas neekolas force-pushed the 08-06-write_to_ledger_from_indexer branch from cdc1a5c to 9a8d5b7 Compare September 2, 2025 05:51
@neekolas neekolas force-pushed the 08-27-add_fee_estimator_and_enable_fees branch from cb08bc4 to 5f77193 Compare September 2, 2025 13:14
@neekolas neekolas force-pushed the 08-06-write_to_ledger_from_indexer branch from 9a8d5b7 to 92fadc0 Compare September 2, 2025 13:14
@neekolas neekolas force-pushed the 08-27-add_fee_estimator_and_enable_fees branch from 5f77193 to f7d0640 Compare September 2, 2025 13:18
@neekolas neekolas force-pushed the 08-06-write_to_ledger_from_indexer branch from 92fadc0 to a1a2b83 Compare September 2, 2025 13:18
@neekolas neekolas force-pushed the 08-27-add_fee_estimator_and_enable_fees branch from f7d0640 to c69cb89 Compare September 2, 2025 13:24
@neekolas neekolas force-pushed the 08-06-write_to_ledger_from_indexer branch from a1a2b83 to 4d288d4 Compare September 2, 2025 13:24
@neekolas neekolas force-pushed the 08-27-add_fee_estimator_and_enable_fees branch from c69cb89 to 639eb4c Compare September 2, 2025 13:28
@neekolas neekolas force-pushed the 08-06-write_to_ledger_from_indexer branch 2 times, most recently from 84f1b17 to 423eadb Compare September 2, 2025 13:37
@neekolas neekolas force-pushed the 08-27-add_fee_estimator_and_enable_fees branch from 639eb4c to 4132c61 Compare September 2, 2025 13:37
@neekolas neekolas force-pushed the 08-06-write_to_ledger_from_indexer branch from 423eadb to 46e3ef3 Compare September 2, 2025 14:05
@neekolas neekolas force-pushed the 08-27-add_fee_estimator_and_enable_fees branch from 4132c61 to 19073e4 Compare September 2, 2025 14:05
@neekolas neekolas force-pushed the 08-06-write_to_ledger_from_indexer branch from 46e3ef3 to 487940b Compare September 2, 2025 14:08
@neekolas neekolas force-pushed the 08-27-add_fee_estimator_and_enable_fees branch from 19073e4 to 01a5e7c Compare September 2, 2025 14:08
@neekolas neekolas force-pushed the 08-06-write_to_ledger_from_indexer branch from 487940b to a0fe85b Compare September 2, 2025 14:13
@neekolas neekolas force-pushed the 08-27-add_fee_estimator_and_enable_fees branch 2 times, most recently from 7a5f4e9 to e17cba4 Compare September 2, 2025 14:22
@neekolas neekolas force-pushed the 08-06-write_to_ledger_from_indexer branch from a0fe85b to 4492e4c Compare September 2, 2025 14:22
@neekolas neekolas force-pushed the 08-27-add_fee_estimator_and_enable_fees branch from e17cba4 to aea804e Compare September 2, 2025 14:23
@neekolas neekolas force-pushed the 08-06-write_to_ledger_from_indexer branch from 4492e4c to 260f23b Compare September 2, 2025 14:23
@graphite-app graphite-app bot changed the base branch from 08-06-write_to_ledger_from_indexer to graphite-base/1083 September 2, 2025 19:22
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.

2 participants