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

Add validator data retention by pubkey #102

Merged

Conversation

aBMania
Copy link
Contributor

@aBMania aBMania commented Feb 28, 2024

Hello,

I needed to retain data indefinitly for certain pubkeys and saw you already had a retain []phase0.ValidatorIndex parameter in pruning methods PruneValidatorEpochSummaries and PruneValidatorBalances.

I've made the choice to change validator index to pubkey since I know ahead of time which pubkey are going to be my validator, but not the indices. So i can set all my pubkeys even if my deposits are not yet made. Could do a quick adaptation to handle both index and pubkeys.

Thanks,
Sylvain

@aBMania aBMania force-pushed the feature/validator-prune-retain-pubkey branch from a542bf3 to a3194a7 Compare February 28, 2024 10:03
@aBMania aBMania force-pushed the feature/validator-prune-retain-pubkey branch from a3194a7 to 728083b Compare February 28, 2024 10:09
Copy link
Collaborator

@mcdee mcdee left a comment

Choose a reason for hiding this comment

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

Thanks for this PR. In general it looks good, there are a few items to address.

One question: have you analyzed the runtime of the DELETE with and without USING? If it is significantly longer in the latter case due to the join then it may make sense to rewrite the query builder so that it only includes USING if there are pubkeys to retain.

@@ -518,7 +518,7 @@ WHERE f_validator_index = $1
}

// PruneValidatorEpochSummaries prunes validator epoch summaries up to (but not including) the given point.
func (s *Service) PruneValidatorEpochSummaries(ctx context.Context, to phase0.Epoch, retain []phase0.ValidatorIndex) error {
func (s *Service) PruneValidatorEpochSummaries(ctx context.Context, to phase0.Epoch, retainPubkeys []phase0.BLSPubKey) error {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we can keep this value as retain given that its type is BLSPubKey

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated !

Comment on lines 550 to 551
pubkeyBytes := make([]byte, len(pubkey))
copy(pubkeyBytes, pubkey[:])
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this required? Could it be replaced by just pubKey[:] to reduce allocations and copying?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Replacing by pubKey[:] would work with 1.22 go for loops.
It does not work with 1.21 go (project use 1.20 go, and i did not want to change version)

See example here: https://go.dev/play/p/K5u3iVSeWe_e

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think you should be able to avoid that by only using the loop variable:

	for i := range retain {
		pubkeysBytes = append(pubkeysBytes, retain[i][:])
	}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, that's better ! Thanks.

@@ -716,7 +716,7 @@ func validatorBalanceFromRow(rows pgx.Rows) (*chaindb.ValidatorBalance, error) {
}

// PruneValidatorBalances prunes validator balances up to (but not including) the given epoch.
func (s *Service) PruneValidatorBalances(ctx context.Context, to phase0.Epoch, retain []phase0.ValidatorIndex) error {
func (s *Service) PruneValidatorBalances(ctx context.Context, to phase0.Epoch, retainPubkeys []phase0.BLSPubKey) error {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same comment as above on variable name.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated !

retainPubkeysBytes := make([][]byte, 0, len(retainPubkeys))

for _, pubkey := range retainPubkeys {
pubkeyBytes := make([]byte, len(pubkey))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same comment as above on variable creation.

@@ -104,6 +108,25 @@ func WithValidatorSummaries(enabled bool) Parameter {
})
}

// WithvalidatorRetainPubkeys states if the module should retain balance and epoch summaries for a subset of validator.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please update comment to match the function.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated !

@@ -104,6 +108,25 @@ func WithValidatorSummaries(enabled bool) Parameter {
})
}

// WithvalidatorRetainPubkeys states if the module should retain balance and epoch summaries for a subset of validator.
func WithvalidatorRetainPubkeys(validatorRetainPubkeys []string) Parameter {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should have a capital "v".

Also, the pubkeys should not be passed in as a string slice. This function should accept []BLSPubKey to allow for catching and reporting errors in the input.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated !

@aBMania aBMania force-pushed the feature/validator-prune-retain-pubkey branch from 1c26370 to 6c4633e Compare March 1, 2024 17:39
@aBMania
Copy link
Contributor Author

aBMania commented Mar 1, 2024

I did not notice any changes in deletion time. (my bottleneck is io)
Also, i guessed postgresql would ignore the join if i did not have a WHERE clause related to the joined table.

But, in any way I've updated so that it only add USING if retains isn't empty.

@mcdee
Copy link
Collaborator

mcdee commented Mar 2, 2024

Thanks for making the changes.

I think that the SQL is now broken in the case that there are no items in retain, it looks like it will not include the USING but still reference t_validators in the WHERE clause.

@aBMania aBMania force-pushed the feature/validator-prune-retain-pubkey branch from 534c4ed to a8633bf Compare March 4, 2024 09:15
@aBMania
Copy link
Contributor Author

aBMania commented Mar 4, 2024

It should be okay now.

I've tested it with and without retain values.

@mcdee mcdee merged commit b1eb4b9 into wealdtech:master Mar 4, 2024
3 checks passed
@mcdee
Copy link
Collaborator

mcdee commented Mar 4, 2024

Thanks for your work on this.

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