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

fix(validation): added da batch validation against state BD desc #1218

Merged
merged 4 commits into from
Nov 12, 2024

Conversation

mtsitrin
Copy link
Contributor

refactored nextSequencer validation

PR Standards

Opening a pull request should be able to meet the following requirements

--

PR naming convention: https://hackmd.io/@nZpxHZ0CT7O5ngTp0TP9mg/HJP_jrm7A


Close #XXX

<-- Briefly describe the content of this pull request -->

For Author:

  • Targeted PR against correct branch
  • included the correct type prefix in the PR title
  • Linked to Github issue with discussion and accepted design
  • Targets only one github issue
  • Wrote unit and integration tests
  • All CI checks have passed
  • Added relevant godoc comments

For Reviewer:

  • confirmed the correct type prefix in the PR title
  • Reviewers assigned
  • confirmed all author checklist items have been addressed

After reviewer approval:

  • In case targets main branch, PR should be squashed and merged.
  • In case PR targets a release branch, PR should be rebased.

refactored nextSequencer validation
block/slvalidator.go Outdated Show resolved Hide resolved
// last block of the batch
lastDABlock := daBlocks[len(daBlocks)-1]
expectedNextSeqHash := lastDABlock.Header.SequencerHash
if slBatch.NextSequencer != slBatch.Sequencer {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. instead of using state proposer, doing slBatch.NextSequencer != slBatch.Sequencer to check for a change
  2. skipped UpdateSequencerSetFromSL as we can assume sync with SL metadata

@mtsitrin mtsitrin linked an issue Nov 11, 2024 that may be closed by this pull request
omritoptix
omritoptix previously approved these changes Nov 11, 2024
Copy link
Contributor

@omritoptix omritoptix left a comment

Choose a reason for hiding this comment

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

looks good though didn't figure out the extra validation of height vs end height on the retriever.

@@ -47,6 +47,12 @@ func (m *Manager) ApplyBatchFromSL(slBatch *settlement.Batch) error {
m.blockCache.Delete(block.Header.Height)
}
}

// validate the batch applied successfully and we are at the end height
Copy link
Contributor

Choose a reason for hiding this comment

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

if the batch isn't applied succesfully wouldn't we get an err from the applyBlockWithFraudHandling ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we're looping over for i, block := range batch.Blocks, which data on the DA
it can be empty/missing

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 I got this @mtsitrin . Is it related to rollback on L1 truncating state info?

@@ -47,7 +47,7 @@ func (v *SettlementValidator) ValidateStateUpdate(batch *settlement.ResultRetrie
for height := batch.StartHeight; height <= batch.EndHeight; height++ {
source, err := v.blockManager.Store.LoadBlockSource(height)
if err != nil {
v.logger.Error("load block source", "error", err)
// v.logger.Error("load block source", "error", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

i dont think you need to remove this log. this will just happen in case no block is stored for the height, which should not happen, i think, because there will be always a block applied for the validated height.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll add the log back.
But I think it can happen
if u at height H, and the state info is [H-1, H+100],
u'll have 100 logs of it

Copy link
Contributor

@srene srene Nov 12, 2024

Choose a reason for hiding this comment

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

im not sure this can happen. if you are at height h, and there is a new state update for h+100, then the node will sync first to height h+100, and then validate for the whole state info. upon reception of a new state update where endheight is higher than node height, it first calls the sync loop and from the sync loop it triggers validation once blocks are applied. so when a state info is validated the block should exist locally always, unless there is a bug.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes u right
it actually handled by the validation added to the ApplyBatchFromSL

block/slvalidator.go Show resolved Hide resolved
block/slvalidator.go Outdated Show resolved Hide resolved
@mtsitrin mtsitrin merged commit 3c33a48 into main Nov 12, 2024
4 checks passed
@mtsitrin mtsitrin deleted the fix/DA_validation branch November 12, 2024 14:14
block/retriever.go Show resolved Hide resolved
block/retriever.go Show resolved Hide resolved
@@ -47,6 +47,12 @@ func (m *Manager) ApplyBatchFromSL(slBatch *settlement.Batch) error {
m.blockCache.Delete(block.Header.Height)
}
}

// validate the batch applied successfully and we are at the end height
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 I got this @mtsitrin . Is it related to rollback on L1 truncating state info?

block/slvalidator.go Outdated Show resolved Hide resolved
@@ -84,8 +82,12 @@ func (v *SettlementValidator) ValidateStateUpdate(batch *settlement.ResultRetrie
if errors.Is(checkBatchResult.Error, da.ErrBlobNotIncluded) {
return types.NewErrStateUpdateBlobNotAvailableFraud(batch.StateIndex, string(batch.MetaData.DA.Client), batch.MetaData.DA.Height, hex.EncodeToString(batch.MetaData.DA.Commitment))
}

// FIXME: how to handle non-happy case? not returning error?
continue
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
continue

Comment on lines +148 to +149
if numSLBlocks != numSlBDs || numDABlocks < numSlBDs {
return types.NewErrStateUpdateNumBlocksNotMatchingFraud(slBatch.EndHeight, numSLBlocks, numSLBlocks, numDABlocks)
Copy link
Contributor

Choose a reason for hiding this comment

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

why do we check numSLBlocks != numSlBDs . Isn't it guaranteed to be true by the hub?

block/slvalidator.go Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

panics where there’s missing data in the DA
4 participants