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

feat: prune used merkle proof #218

Merged
merged 12 commits into from
Dec 16, 2024
Merged

feat: prune used merkle proof #218

merged 12 commits into from
Dec 16, 2024

Conversation

Lazar955
Copy link
Member

@Lazar955 Lazar955 requested a review from gitferry December 12, 2024 15:13
@Lazar955 Lazar955 linked an issue Dec 12, 2024 that may be closed by this pull request
@Lazar955
Copy link
Member Author

Hm, it's expected for double sign test to fail now, as the proof is deleted

Copy link
Member

@gitferry gitferry left a comment

Choose a reason for hiding this comment

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

Keep thinking about this. I feel safer if we make it a CLI: fpd unsafe-prune-merkle-proof [eots-pk] --chain-id --up-to-height where --chain-id is required. If the user does not specify --up-to-height, the pruning is up to the fp's last voted height.

This would require db schema change as follows:

  1. the current key is the randomness number itself, which does not support range query by height. Therefore we need to add height to the key
  2. given that the fpd might store different fps with different chain id, we need also add chainid and fp public key in the key like we did for signing record
    func getSignRecordKey(chainID, pk []byte, height uint64) []byte {

wdyt?

@bap2pecs
Copy link
Contributor

Keep thinking about this. I feel safer if we make it a CLI: fpd unsafe-prune-merkle-proof [eots-pk] --chain-id --up-to-height where --chain-id is required. If the user does not specify --up-to-height, the pruning is up to the fp's last voted height.

This would require db schema change as follows:

  1. the current key is the randomness number itself, which does not support range query by height. Therefore we need to add height to the key

  2. given that the fpd might store different fps with different chain id, we need also add chainid and fp public key in the key like we did for signing record

    func getSignRecordKey(chainID, pk []byte, height uint64) []byte {

wdyt?

i am not familiar with this db schema but the first point makes sense.

for 2), I don't know if it's necessary to change db because a FP can only register for one consumer chain. So we can simply query the FP's consumer chain id to see if it matches with what's passed in to the CLI

meta-thought: you guys might need to think about data migration for backward compatibility issue.

@gitferry
Copy link
Member

for 2), I don't know if it's necessary to change db because a FP can only register for one consumer chain. So we can simply query the FP's consumer chain id to see if it matches with what's passed in to the CLI

We need to change db to add height as the key for each randomness along with the proof. However, a fpd may store randomness for different fps, so fp public key is also neede in the key. Probably we don't need chainid as the key for now as fp is unique across different chains but I think it's worth keeping it for potential range query for different chains

meta-thought: you guys might need to think about data migration for backward compatibility issue.

my understanding for this is that after we launch phase-2, for any db schema change later on we need to consider backward compatibility. Do you think we need to do anything before the launch?

@bap2pecs
Copy link
Contributor

my understanding for this is that after we launch phase-2, for any db schema change later on we need to consider backward compatibility. Do you think we need to do anything before the launch?

yeah i think it makes sense to only consider it after mainnet launch.

@Lazar955 Lazar955 changed the title chore: prune used merkle proof feat: prune used merkle proof Dec 13, 2024
@@ -488,6 +488,63 @@ func runCommandEditFinalityDescription(cmd *cobra.Command, args []string) error
return nil
}

// CommandUnsafeDeleteMerkleProof removes merkle proof
func CommandUnsafeDeleteMerkleProof() *cobra.Command {
var cmd = &cobra.Command{
Copy link
Contributor

Choose a reason for hiding this comment

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

should we have a command to delete this? kkk seems a bit scary

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, maybe more docs about the consequences?

Copy link
Member

Choose a reason for hiding this comment

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

I would use prune other than remove which seems less scary. Let's add a long description of the consequences. The user should ensure that up to the pruning height, the fp has already voted or it does not have voting power for those blocks

@@ -133,4 +171,37 @@ func (s *PubRandProofStore) GetPubRandProofList(pubRandList []*btcec.FieldVal) (
return proofBytesList, nil
}

// TODO: delete function?
// RemovePubRandProofList removes all proofs up to the target height
func (s *PubRandProofStore) RemovePubRandProofList(chainID []byte, pk []byte, targetHeight uint64) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

lets add a specific unit test for this one?

Copy link
Member Author

Choose a reason for hiding this comment

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

thanks, added in 514b202

Copy link
Contributor

@RafilxTenfen RafilxTenfen left a comment

Choose a reason for hiding this comment

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

utACK, suggestion to add a specific unit test for RemovePubRandProofList

Copy link
Member

@gitferry gitferry left a comment

Choose a reason for hiding this comment

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

Great work!

@@ -488,6 +488,63 @@ func runCommandEditFinalityDescription(cmd *cobra.Command, args []string) error
return nil
}

// CommandUnsafeDeleteMerkleProof removes merkle proof
func CommandUnsafeDeleteMerkleProof() *cobra.Command {
var cmd = &cobra.Command{
Copy link
Member

Choose a reason for hiding this comment

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

I would use prune other than remove which seems less scary. Let's add a long description of the consequences. The user should ensure that up to the pruning height, the fp has already voted or it does not have voting power for those blocks

@@ -1020,3 +1026,8 @@ func (fp *FinalityProviderInstance) GetFinalityProviderSlashedOrJailedWithRetry(

return slashed, jailed, nil
}

// TestGetPubProof only used for tests to get access to the store
func (fp *FinalityProviderInstance) TestGetPubProof(height uint64) ([]byte, error) {
Copy link
Member

Choose a reason for hiding this comment

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

This is probably not needed as we can access the store by app.GetPubRandProofStore()

@Lazar955 Lazar955 merged commit d8506b6 into main Dec 16, 2024
12 checks passed
@Lazar955 Lazar955 deleted the lazar/prune-proof branch December 16, 2024 10:31
filippos47 pushed a commit that referenced this pull request Feb 10, 2025
* Init
* Update babylon-private reference
* Revert "CI: Remove redundant SSH key logic (#218)"
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.

Prune used merkle proof from db
4 participants