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: Implement fraudproof generation mode in cosmos-sdk #250

Conversation

Manav-Aggarwal
Copy link
Member

@Manav-Aggarwal Manav-Aggarwal commented Aug 6, 2022

Description

Before: When an optimint full node finds a fraudulent block, it tells cosmos-sdk to go into fraudproof generation mode.

After: optimint can supply cosmos-sdk with a fraudulent block and tell it to actually generate a fraudproof.

In the fraudproof generation mode, a cosmos-sdk app reverts its state to a previous state before the fraudulent block was applied and enables tracing for modules specified by optimint.

Parts covered from the cycle of a fraudproof:

Optimint Full Node (Producer of fraudproof)
2. In the fraudproof generation mode, a cosmos-sdk app reverts its state to a previous state before the fraudulent block is applied and enables tracing.

Builds on top of #256

Closes: #249


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • included the correct type prefix in the PR title
  • [ x added ! to the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • followed the guidelines for building modules
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • included comments for documenting Go code
  • updated the relevant documentation or specification
  • reviewed "Files changed" and left comments if necessary
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed ! in the type prefix if API or client breaking change
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic
  • reviewed API design and naming
  • reviewed documentation is accurate
  • reviewed tests and test coverage
  • manually tested (if applicable)

@Manav-Aggarwal Manav-Aggarwal added C: Cevmos Changes related to the cevmos branches block-fraud-proofs Block Fraud Proofs (Generation and verification) C:Store labels Aug 6, 2022
@Manav-Aggarwal Manav-Aggarwal self-assigned this Aug 6, 2022
@Manav-Aggarwal Manav-Aggarwal linked an issue Aug 6, 2022 that may be closed by this pull request
@github-actions github-actions bot added the C:orm label Aug 6, 2022
@Manav-Aggarwal Manav-Aggarwal changed the title Implement fraudproof generation mode in cosmos-sdk feat: Implement fraudproof generation mode in cosmos-sdk Aug 6, 2022
@Manav-Aggarwal Manav-Aggarwal force-pushed the manav/add-fraudproof-generation-mode branch 2 times, most recently from 1f37db3 to 8bdd5ae Compare August 9, 2022 18:11
@github-actions github-actions bot removed the C:orm label Aug 9, 2022
@Manav-Aggarwal Manav-Aggarwal force-pushed the manav/add-fraudproof-generation-mode branch 5 times, most recently from 82f1017 to 0391f77 Compare August 11, 2022 07:35
// make list of options to pass by parsing fraudproof
app := NewBaseApp(appName, logger, db, txDecoder, options...)

app.router = router
Copy link
Member Author

Choose a reason for hiding this comment

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

what’s the best way to reuse a route from a one app B1 to another app B2? Just passing in the same router from B1 doesn’t seem to work because during the route it uses B1 but I want it to use B2.

// make list of options to pass by parsing fraudproof
app := NewBaseApp(appName, logger, db, txDecoder, options...)

app.router = router
Copy link
Member Author

Choose a reason for hiding this comment

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

what’s the best way to reuse a route from a one app B1 to another app B2? Just passing in the same router from B1 doesn’t seem to work because during the route it uses B1 but I want it to use B2.

Copy link
Member

@evan-forbes evan-forbes Aug 11, 2022

Choose a reason for hiding this comment

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

not 100% sure of the context here, mind elaborating or pointing me to something?

Copy link
Member

Choose a reason for hiding this comment

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

when creating fraud proofs, we're creating an entirely new app, correct? so why do we need to pass the same router?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, we're creating an entirely new app but functionally we'd want the same routing method.

Copy link
Member

Choose a reason for hiding this comment

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

sorry, I'm out of the loop, isn't the router stateless? what's the reason we need the same exact one?

also, in most cases we'll be working with the msgServiceRouter, correct?

Copy link
Member

Choose a reason for hiding this comment

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

or I guess we'll need both if we want to support legacy stuff

Copy link
Member Author

Choose a reason for hiding this comment

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

sorry I should clarify more, yes the router is stateless. But we'd still like the same function as routes to be used in the new baseapp. No state just logically.

Yes in most cases we'll be using msgServiceRouter, is that also something I should initialize using the previous app's msgServiceRouter?

@Manav-Aggarwal Manav-Aggarwal marked this pull request as ready for review August 11, 2022 16:14
@Manav-Aggarwal Manav-Aggarwal changed the base branch from v0.46.0-with-smt to manav/add-substore-level-fp-verification August 11, 2022 17:09
@Manav-Aggarwal Manav-Aggarwal force-pushed the manav/add-substore-level-fp-verification branch from 41c96f1 to a746788 Compare August 12, 2022 01:28
@Manav-Aggarwal Manav-Aggarwal force-pushed the manav/add-fraudproof-generation-mode branch from 8500a19 to ce43a38 Compare August 12, 2022 01:28
options = append(options, SetTracerFor(storeKey.Name(), storeKeyToSubstoreTraceBuf[storeKey.Name()]))
options = append(options, AppOptionFunc(routerOpts[storeKey.Name()]))
}
newApp, err := SetupBaseAppFromParams(app.name+"WithTracing", app.logger, dbm.NewMemDB(), app.txDecoder, storeKeyNames, app.LastBlockHeight()+1, storeToLoadFrom, options...)

Choose a reason for hiding this comment

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

I would prefer a separate variable like newBlockHeight = app.LastBlockHeight()+1 at the top of this method and then using it here.

@@ -32,7 +32,7 @@ func SetSubstoreTracer(w io.Writer) StoreOption {

// SetTracerFor provides a BaseApp option function that sets the
// tracer for a substore with given skey inside a multistore.
func SetTracerFor(skey storetypes.StoreKey, w io.Writer) StoreOption {
func SetTracerFor(skey string, w io.Writer) StoreOption {
return func(cfg *multi.StoreParams, _ uint64) error {

Choose a reason for hiding this comment

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

Why change from storetypes.StoreKey to string?

Copy link
Member Author

Choose a reason for hiding this comment

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

For a StoreKey, it is newly created in SetupBaseAppFromParams using NewKVStoreKey. Since SetTracerFor is called before that, we don't have access to that newly created StoreKey which is why we just simplify it to a string. If I were to use StoreKey of the previous app, even though it would have the same underlying name, the object itself would be different so string is a better shared object than StoreKey.

@Manav-Aggarwal
Copy link
Member Author

everything is moved to cosmos-sdk-rollmint repo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
block-fraud-proofs Block Fraud Proofs (Generation and verification) C: Cevmos Changes related to the cevmos branches C:Store
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement fraudproof generation mode in cosmos-sdk
3 participants