-
Notifications
You must be signed in to change notification settings - Fork 255
feat: add block rollback support #2499
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
Merged
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
1736406
Add rollback command and block rollback support
julienrbrt 7866d1b
Implement state rollback to arbitrary block height
julienrbrt 7cc1c71
updates
julienrbrt e85a8ce
Fix Rollback to set height directly instead of using SetHeight
julienrbrt b9ff07d
add tests
julienrbrt b3cb4a2
add rollback to exec api
julienrbrt ef081e6
Implement atomic rollback for KVExecutor and add tests
julienrbrt bbca2ba
Merge branch 'main' into julien/rollback
julienrbrt b8004b7
improve kv executor
julienrbrt c87c3a7
remove rollback from exec interface, use only store commands
julienrbrt 41bb318
Merge branch 'main' into julien/rollback
julienrbrt e84b4c9
remove binary + add to gitignore
julienrbrt bb6a175
Merge branch 'main' into julien/rollback
julienrbrt 2e8ca9d
Merge branch 'main' into julien/rollback
julienrbrt 26c024d
Merge branch 'main' into julien/rollback
tac0turtle 6c2cbab
Merge branch 'main' into julien/rollback
julienrbrt 75b7706
Merge branch 'main' into julien/rollback
julienrbrt 8ae3b63
Merge branch 'main' into julien/rollback
julienrbrt 18b3cbb
remove print
julienrbrt 139779f
Merge branch 'main' into julien/rollback
julienrbrt ede5086
Prevent rollback below DA included height
julienrbrt eacea0a
lint
julienrbrt e3d67c6
Merge branch 'main' into julien/rollback
julienrbrt 05bedab
fix typo
julienrbrt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| package cmd | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "strconv" | ||
|
|
||
| kvexecutor "github.com/evstack/ev-node/apps/testapp/kv" | ||
| rollcmd "github.com/evstack/ev-node/pkg/cmd" | ||
| "github.com/evstack/ev-node/pkg/store" | ||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| var RollbackCmd = &cobra.Command{ | ||
| Use: "rollback <height>", | ||
| Short: "Rollback the testapp node", | ||
| Args: cobra.RangeArgs(0, 1), | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| nodeConfig, err := rollcmd.ParseConfig(cmd) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| ctx, cancel := context.WithCancel(context.Background()) | ||
| defer cancel() | ||
|
|
||
| datastore, err := store.NewDefaultKVStore(nodeConfig.RootDir, nodeConfig.DBPath, "testapp") | ||
| if err != nil { | ||
| return err | ||
| } | ||
| storeWrapper := store.New(datastore) | ||
|
|
||
| executor, err := kvexecutor.NewKVExecutor(nodeConfig.RootDir, nodeConfig.DBPath) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| cmd.Println("Starting rollback operation") | ||
| currentHeight, err := storeWrapper.Height(ctx) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to get current height: %w", err) | ||
| } | ||
|
|
||
| var targetHeight uint64 = currentHeight - 1 | ||
| if len(args) > 0 { | ||
| targetHeight, err = strconv.ParseUint(args[0], 10, 64) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to parse target height: %w", err) | ||
| } | ||
| } | ||
|
|
||
| // rollback ev-node store | ||
| if err := storeWrapper.Rollback(ctx, targetHeight); err != nil { | ||
| return fmt.Errorf("rollback failed: %w", err) | ||
| } | ||
|
|
||
| // rollback execution store | ||
| if err := executor.Rollback(ctx, targetHeight); err != nil { | ||
| return fmt.Errorf("rollback failed: %w", err) | ||
| } | ||
|
|
||
| cmd.Println("Rollback completed successfully") | ||
| return nil | ||
| }, | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,7 @@ func main() { | |
| rollcmd.NetInfoCmd, | ||
| rollcmd.StoreUnsafeCleanCmd, | ||
| rollcmd.KeysCmd(), | ||
| cmds.RollbackCmd, | ||
| initCmd, | ||
| ) | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,7 @@ import ( | |
| "github.com/libp2p/go-libp2p/core/crypto" | ||
| "github.com/rs/zerolog" | ||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/mock" | ||
| "github.com/stretchr/testify/require" | ||
|
|
||
| coresequencer "github.com/evstack/ev-node/core/sequencer" | ||
|
|
@@ -28,6 +29,7 @@ import ( | |
| "github.com/evstack/ev-node/pkg/signer/noop" | ||
| "github.com/evstack/ev-node/pkg/store" | ||
| evSync "github.com/evstack/ev-node/pkg/sync" | ||
| "github.com/evstack/ev-node/test/mocks" | ||
| "github.com/evstack/ev-node/types" | ||
| ) | ||
|
|
||
|
|
@@ -200,13 +202,18 @@ func setupBlockManager(t *testing.T, ctx context.Context, workDir string, mainKV | |
| require.NoError(t, err) | ||
| require.NoError(t, dataSyncService.Start(ctx)) | ||
|
|
||
| mockExecutor := mocks.NewMockExecutor(t) | ||
| mockExecutor.On("InitChain", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(bytesN(32), uint64(10_000), nil).Maybe() | ||
| mockExecutor.On("ExecuteTxs", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(bytesN(32), uint64(10_000), nil).Maybe() | ||
| mockExecutor.On("SetFinal", mock.Anything, mock.Anything).Return(nil).Maybe() | ||
|
|
||
| result, err := NewManager( | ||
| ctx, | ||
| signer, | ||
| nodeConfig, | ||
| genesisDoc, | ||
| store.New(mainKV), | ||
| &mockExecutor{}, | ||
| mockExecutor, | ||
| coresequencer.NewDummySequencer(), | ||
| nil, | ||
| blockManagerLogger, | ||
|
|
@@ -221,24 +228,6 @@ func setupBlockManager(t *testing.T, ctx context.Context, workDir string, mainKV | |
| return result, headerSyncService, dataSyncService | ||
| } | ||
|
|
||
| type mockExecutor struct{} | ||
|
|
||
| func (m mockExecutor) InitChain(ctx context.Context, genesisTime time.Time, initialHeight uint64, chainID string) (stateRoot []byte, maxBytes uint64, err error) { | ||
| return bytesN(32), 10_000, nil | ||
| } | ||
|
|
||
| func (m mockExecutor) GetTxs(ctx context.Context) ([][]byte, error) { | ||
| panic("implement me") | ||
| } | ||
|
|
||
| func (m mockExecutor) ExecuteTxs(ctx context.Context, txs [][]byte, blockHeight uint64, timestamp time.Time, prevStateRoot []byte) (updatedStateRoot []byte, maxBytes uint64, err error) { | ||
| return bytesN(32), 10_000, nil | ||
| } | ||
|
|
||
| func (m mockExecutor) SetFinal(ctx context.Context, blockHeight uint64) error { | ||
| return nil | ||
| } | ||
|
|
||
| var rnd = rand.New(rand.NewSource(1)) //nolint:gosec // test code only | ||
|
|
||
| func bytesN(n int) []byte { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -276,8 +276,6 @@ func NewServiceHandler(store store.Store, peerManager p2p.P2PRPC, logger zerolog | |
|
|
||
| mux := http.NewServeMux() | ||
|
|
||
| fmt.Println("Registering gRPC reflection service...") | ||
|
|
||
| compress1KB := connect.WithCompressMinBytes(1024) | ||
| reflector := grpcreflect.NewStaticReflector( | ||
| rpc.StoreServiceName, | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check failure
Code scanning / CodeQL
Log entries created from user input High test
Copilot Autofix
AI 8 months ago
To fix the problem, we need to sanitize the user-provided
keybefore logging it. Since the logs are plain text, the recommended approach is to remove any newline (\n) and carriage return (\r) characters from thekeybefore including it in the log message. This can be done usingstrings.ReplaceAll. The fix should be applied directly at the point where the log message is constructed, i.e., inapps/testapp/kv/kvexecutor.goat line 59. We need to ensure that thestringspackage is imported (it already is), so no new imports are needed.