8000 ADR101:Fixing the retain height set logic by jmalicevic · Pull Request #1261 · cometbft/cometbft · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

ADR101:Fixing the retain height set logic #1261

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

Conversation

jmalicevic
Copy link
Contributor

This PR addresses comments made internally on potential corner cases where the retain height is not accepted in case any height height is set , even though it is not the height used for pruning.

Example

appRetainHeight:100
dataCompanionRetainHeight:20

Data companion wants to set the height to 50.
The old logic would refuse this because the application retain height is set to 100 and we assume blocks to 100 are pruned. However, we will prune only up until the lower of the two retain heights (20) in this case. So it makes sense to accept this value.

If the application retain height was the only one set, we would then refuse this as a way to signal to the data companion that the request height is invalid and those blocks might have indeed been pruned.

… not accepted only if it is less than the current min height.

Fixed potential corner case in checking for the minimum height in case no retain height is set.
This corner case should not be present in practice as the app retain height is expected to be set
but it is a safety check in case the logic of setting it on startup changes down the road.
@jmalicevic jmalicevic added the P:storage-optimization Priority: Give operators greater control over storage and storage optimization label Aug 17, 2023
@jmalicevic jmalicevic added this to the 2023-Q3 milestone Aug 17, 2023
@jmalicevic jmalicevic requested a review from a team as a code owner August 17, 2023 13:30
@jmalicevic jmalicevic requested a review from a team August 17, 2023 13:30
Copy link
Contributor
@andynog andynog left a comment

Choose a reason for hiding this comment

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

added a few comments in regards the new logic

currentAppRetainHeight = height
currentMinRetainHeight := p.findMinRetainHeight()
if height < currentMinRetainHeight {
return ErrPrunerCannotLowerRetainHeight
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure if this logic returns the desirable outcome. For example, let's assume the following scenario:

DCRetainHeight AppRetainHeight Height
98 100 99

This logic would return a currentMinRetainHeight = 98 and since height (99) > currentMinRetainHeight (99) this would set the AppRetainHeight to 99 but it was already at 100, so after executing this logic you would end up with:

DCRetainHeight AppRetainHeight Height
98 99 99

I'm thinking that the logic in p.findMinRetainHeight() shouldn't be used in the logic to Set the retain heights, because it mixes the DC and the App retain height which might make the things more complicated. Maybe we just need to check here if the current AppRetainHeight is lower or not and set it accordingly.

Then in the pruner logic to check between the AppRetainHeight and DCRetainHeight whichever is lower then we use the lower one (the one returned by p.findMinRetainHeight

Copy link
Contributor

Choose a reason for hiding this comment

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

Can we perhaps introduce a comprehensive set of tests for the desired behaviour?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

so, we will probably adopt Thane's solution but for completness I'll repeat my comment from Slack here. I don't see it as particularly wrong if the app changes it's mind if the current retain height it had set before was not use yet (because there was another lower one set).

currentMinHeight := p.findMinRetainHeight()

if height < currentMinHeight {
return ErrPrunerCannotLowerRetainHeight
Copy link
Contributor

Choose a reason for hiding this comment

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

same comment as above should apply here

go.sum Outdated
@@ -325,6 +325,7 @@ github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre
github.com/go-sql-driver/mysql v1.7.0 h1:ueSltNNllEqE3qcWBTD0iQd3IpL/6U+mJxLkazJ7YPc=
github.com/go-sql-driver/mysql v1.7.0/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE=
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, what are these new dependencies for...

Copy link
Contributor

Choose a reason for hiding this comment

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

No go.mod updates, so these should be removed by a go mod tidy.

state/pruner.go Outdated
}
currentAppRetainHeight, err := p.stateStore.GetApplicationRetainHeight()
noAppRetainHeight := false
_, err := p.stateStore.GetCompanionBlockRetainHeight()
Copy link
Contributor

Choose a reason for hiding this comment

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

What is this get operation for? Checking if the key already exists in the database?

Copy link
Contributor

Choose a reason for hiding this comment

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

no, it seems mostly to check if there's no error with the key in the database (e.g. < 0). Do we really need this ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are totally right, this was left over from the version where I checked the new height of the dc companion is not lower than its own previous height, which I deemed not needed anymore because of the comparison against the minimum height ..allowing it to set a lower height in case it's own height was not the miminum.

@mzabaluev
Copy link
Contributor
mzabaluev commented Aug 18, 2023

I think I get a part of the problem @jmalicevic is on to: at startup, we l 8000 ack explicit means to determine if the data companion will be there to prune. The previous behaviour was to prune to the height the application has commanded, but if we just do that, we might lose data the companion has not retrieved yet.

Can we use the configuration setting grpc.privileged.pruning_service.enabled as a guide to not let the application-commanded pruning height bump up the effective pruning height above the companion-commanded height (which should be considered 0 before any pruning requests are executed)?

@thanethomson
Copy link
Contributor
thanethomson commented Aug 18, 2023

I think I get a part of the problem @jmalicevic is on to: at startup, we lack explicit means to determine if the data companion will be there to prune. The previous behaviour was to prune to the height the application has commanded, but if we just do that, we might lose data the companion has not retrieved yet.

Why not just honour the storage.pruning.data_companion.enabled flag?

If pruning's configured to not respect the data companion (i.e. that flag's set to false) and the application prunes blocks that the operator may have wanted the companion to obtain, that's just too bad. It's misconfiguration. They'll have to sync again from the desired height.

@mzabaluev
Copy link
Contributor

Why not just honour the storage.pruning.data_companion.enabled flag?

Oh yes, I forgot we have that one too.

@jmalicevic
Copy link
Contributor Author

Closing becuase we will adopt the logic in #1271

@jmalicevic jmalicevic closed this Aug 22, 2023
@zrbecker zrbecker deleted the jasmina/adapt-retain-height-logic branch February 7, 2025 17:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P:storage-optimization Priority: Give operators greater control over storage and storage optimization
Projects
No 54BD open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants
0