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

[NONEVM-714] - Add multiple blocks aggregation functionality to Block History Estimator #896

Open
wants to merge 14 commits into
base: develop
Choose a base branch
from

Conversation

Farber98
Copy link
Contributor

@Farber98 Farber98 commented Oct 18, 2024

Description:

This PR Introduces the MultipleBlocksEstimator that tries to get the desiredBlockCount most recent blocks to determine a more stable compute unit price.

How It Works:

  • Configuration: BlockHistoryDepth and FeeEstimatorMode are used to configure this estimator.

  • Fetch Recent Blocks: Tries to retrieve specified number of the latest confirmed blocks from latest slots based on the configured BlockHistoryDepth. Not all slots have a block.

  • Concurrent Processing:: Fetches each block concurrently while limiting the number of simultaneous operations to prevent rate limiting.

  • Extract and Aggregate Fees: Parses each block to extract compute unit prices from transactions. Calculates the median compute unit price for each block.

  • Determine Overall Median: Aggregates the median prices from all fetched blocks. Computes the overall median to set as the current base compute unit price, ensuring it stays within predefined minimum and maximum config limits.

@cl-sonarqube-production
Copy link

Quality Gate failed Quality Gate failed

Failed conditions
3 New Blocker Issues (required ≤ 0)
E Security Rating on New Code (required ≥ A)

See analysis details on SonarQube

Catch issues before they fail your Quality Gate with our IDE extension SonarLint SonarLint

@Farber98
Copy link
Contributor Author

SonarQube thinks some account addresses in the json file are IBM API Keys. That's why the low score.

image

@Farber98 Farber98 marked this pull request as ready for review October 21, 2024 12:54
@Farber98 Farber98 requested a review from a team as a code owner October 21, 2024 12:54

if desiredBlockCount > MAX_BLOCK_HISTORY_DEPTH {
// Limit the desired block count to maxblockHistoryDepth
desiredBlockCount = MAX_BLOCK_HISTORY_DEPTH
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we should log a warning here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The thing is this code executes once every BlockHistoryPollPeriod, so it may become really noisy.

Wdyt about refactoring and checking/logging during initialization?

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 it might be ok not setting a max block history unless during testing we find some sort of definitive upper limit. Otherwise, we could make a recommendation to CCIP if they want to set a high value to not go over a certain value but we shouldn't make it a hard requirement in the code.

Copy link
Contributor

Choose a reason for hiding this comment

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

Wdyt about refactoring and checking/logging during initialization?

If we do want to keep an upper bound, I think it's better to move this to initialization. But instead of just logging a warning, we should fail initialization so the person running the node can update the configs accordingly.

@@ -31,6 +31,7 @@ var defaultConfigSet = Chain{
BlockHistoryPollPeriod: config.MustNewDuration(5 * time.Second),
ComputeUnitLimitDefault: ptr(uint32(200_000)), // set to 0 to disable adding compute unit limit
EstimateComputeUnitLimit: ptr(false), // set to false to disable compute unit limit estimation
BlockHistoryDepth: ptr(uint64(20)), // number of blocks to fetch for multiple blocks fee estimation
Copy link
Contributor

Choose a reason for hiding this comment

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

Just to keep things consistent with EVM where we can, could we rename this config to BlockHistorySize instead?

Copy link
Contributor

Choose a reason for hiding this comment

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

Also to keep existing behavior of the BHE, we should maybe set this default to 1 to mimic latest block behavior.

Comment on lines +19 to +37
type EstimationMethod int

const (
LatestBlockEstimator EstimationMethod = iota
MultipleBlocksEstimator
)

const MAX_BLOCK_HISTORY_DEPTH = 20

func (em EstimationMethod) String() string {
switch em {
case LatestBlockEstimator:
return "LatestBlock"
case MultipleBlocksEstimator:
return "MultipleBlocks"
default:
return "UnknownMethod"
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we need to introduce an estimation method here. I think we can infer the same thing with using the BlockHistorySize config. Like if BlockHistorySize=1 then we should do the latest block logic, otherwise do the multiple blocks logic

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 just for the unit tests we probably shouldn't commit such a big file. Feel like we should be able to get away with mocking a few blocks in code in block_history_test.go instead.

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.

3 participants