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(manager): state update mishbehavior detection #1130

Merged
merged 37 commits into from
Oct 28, 2024

Conversation

srene
Copy link
Contributor

@srene srene commented Oct 10, 2024

PR Standards

ADR x: State update misbehavior detection

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

--

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


Close #1106

<-- 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.

@srene srene requested a review from a team as a code owner October 10, 2024 15:50
@srene srene self-assigned this Oct 10, 2024
@srene srene marked this pull request as draft October 10, 2024 15:51
@srene srene force-pushed the srene/1106-state-update-mishbehavior branch from 29d9dff to 62ed34e Compare October 11, 2024 11:00
@srene srene force-pushed the srene/1106-state-update-mishbehavior branch 5 times, most recently from 3133aa3 to cd01dd7 Compare October 15, 2024 10:12
@srene srene marked this pull request as ready for review October 15, 2024 10:12
@srene srene marked this pull request as draft October 21, 2024 12:14
@srene srene force-pushed the srene/1128-validation-rpc branch from 651e920 to 5552b77 Compare October 22, 2024 10:39
@srene srene force-pushed the srene/1106-state-update-mishbehavior branch from e6a6e50 to 6726b93 Compare October 22, 2024 13:15
@srene srene marked this pull request as ready for review October 22, 2024 13:28
@srene srene marked this pull request as draft October 23, 2024 08:48
@srene srene force-pushed the srene/1128-validation-rpc branch from c2d36f1 to a62066c Compare October 24, 2024 14:20
@srene srene changed the base branch from srene/1128-validation-rpc to main October 24, 2024 14:31
@srene srene marked this pull request as draft October 25, 2024 11:33
@srene srene marked this pull request as ready for review October 25, 2024 21:14
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.

I think the DRS in-memory management makes the code cumbersome and unnecessary complicated vs just saving DRS per height (like we do with block, commit, proposer) etc and just get it where necessary.

we should strive to keep the code simple vs micro optimizations.

block/block.go Outdated
@@ -122,7 +122,15 @@ func (m *Manager) applyBlock(block *types.Block, commit *types.Commit, blockMeta
m.logger.Error("pruning channel full. skipping pruning", "retainHeight", retainHeight)
}
}

if responses.EndBlock.RollappParamUpdates != nil {
newDRS := m.DRSVersionHistory.AddDRSVersion(block.Header.Height, responses.EndBlock.RollappParamUpdates.Version)
Copy link
Contributor

Choose a reason for hiding this comment

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

Few questions/comments here:

  1. can we have plz a comment explainig why are we saving the history
  2. I get the optimization here but what happens if we get a reboot? than we save a DRS which is not acutally new
  3. I don't think there is an inherent problem just saving the DRS per height (even if not unique - as anyway you don't prevent it now due to (2))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

drs history replaced by storing drs per height.

Comment on lines 72 to 86
// LoadDrsHistoryFromStore loads drs history from store
func (m *Manager) LoadDrsHistoryFromStore() error {
drsHistory, err := m.Store.LoadDRSVersionHistory()
if errors.Is(err, gerrc.ErrNotFound) {
m.logger.Info("failed to find drs history in the store, creating new")
m.DRSVersionHistory = &types.DRSVersionHistory{}
return nil
} else if err != nil {
return fmt.Errorf("get drs version history: %w", err)
}

m.DRSVersionHistory = drsHistory

return nil
}
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
// LoadDrsHistoryFromStore loads drs history from store
func (m *Manager) LoadDrsHistoryFromStore() error {
drsHistory, err := m.Store.LoadDRSVersionHistory()
if errors.Is(err, gerrc.ErrNotFound) {
m.logger.Info("failed to find drs history in the store, creating new")
m.DRSVersionHistory = &types.DRSVersionHistory{}
return nil
} else if err != nil {
return fmt.Errorf("get drs version history: %w", err)
}
m.DRSVersionHistory = drsHistory
return nil
}
// LoadDrsHistoryFromStore loads drs history from store
func (m *Manager) LoadDrsHistoryFromStore() error {
drsHistory, err := m.Store.LoadDRSVersionHistory()
if errors.Is(err, gerrc.ErrNotFound) {
m.logger.Info("failed to find drs history in the store, creating new")
drsHistory = &types.DRSVersionHistory{}
} else if err != nil {
return fmt.Errorf("get drs version history: %w", err)
}
m.DRSVersionHistory = drsHistory
return nil
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this has been removed

return fmt.Errorf("get drs version history: %w", err)
}

m.DRSVersionHistory = drsHistory
Copy link
Contributor

Choose a reason for hiding this comment

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

as to my other comment on the applyBlock - not sure the optimization of saving it in memory and than only saving the uniqe changes in store (which I'm not sure is actually the case) is necessary for optimization.
I'd simply just save the DRS per height and also get rid of the new manager memeber (i.e DRSVersionHistory)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed

block/manager.go Outdated
@@ -161,6 +164,11 @@ func NewManager(
return nil, fmt.Errorf("get initial state: %w", err)
}

err = m.LoadDrsHistoryFromStore()
Copy link
Contributor

Choose a reason for hiding this comment

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

as to my other comment - don't think maintining this in memory is necessary

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

drs history replaced by drs per height in store

block/block.go Outdated
if responses.EndBlock.RollappParamUpdates != nil {
newDRS := m.DRSVersionHistory.AddDRSVersion(block.Header.Height, responses.EndBlock.RollappParamUpdates.Version)
if newDRS {
_, err = m.Store.SaveDRSVersionHistory(m.DRSVersionHistory, nil)
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 we should simply save DRS per height in the store (so the key is per height, similiar to how we save the proposer changes. And prune it when necessary. it will simplify all the DRS management and validation imo)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

omritoptix
omritoptix previously approved these changes Oct 28, 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.

Approved. 2 issues im not sure about but we can address it in seperate issues.

@omritoptix omritoptix merged commit 314003c into main Oct 28, 2024
6 checks passed
@omritoptix omritoptix deleted the srene/1106-state-update-mishbehavior branch October 28, 2024 12:41
@srene
Copy link
Contributor Author

srene commented Oct 28, 2024

da batch is written to celestia without including drs version and last batch, since it is not included when mashall / unmmarshal, but its used when submitting to sl to generate the block descriptors. added an issue to improve it #1171

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.

move drs version to block descriptors instead of state info Detection: State Update Misbehavior - Impl
2 participants