Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 276
fix: making writing atomic#2745
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
Closed
Uh oh!
There was an error while loading. Please reload this page.
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f709b7c
add batching
tac0turtle 21e72b3
refactor to use batching struct
tac0turtle f0fa3c8
add back setheight
tac0turtle f4049c7
Merge branch 'julien/sync-p2p' into marko/atomicity
tac0turtle 6c3df24
add back some changes
tac0turtle a23ea84
remove comment
tac0turtle e11886a
address to hex instead of bytes
tac0turtle File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
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
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 |
|---|---|---|
| @@ -202,15 +202,22 @@ func (e *Executor) initializeState() error { | ||
| AppHash: stateRoot, | ||
| DAHeight: 0, | ||
| } | ||
| // Set store height and save initial state | ||
| batch, err := e.store.NewBatch(e.ctx) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to create batch for initialization: %w", err) | ||
| } | ||
| if err := batch.SetHeight(state.LastBlockHeight); err != nil { | ||
| return fmt.Errorf("failed to set store height: %w", err) | ||
| } | ||
| if err := batch.Commit(); err != nil { | ||
| return fmt.Errorf("failed to commit initial state: %w", err) | ||
| } | ||
| } | ||
| e.setLastState(state) | ||
| // Set store height | ||
| if err := e.store.SetHeight(e.ctx, state.LastBlockHeight); err != nil { | ||
| return fmt.Errorf("failed to set store height: %w", err) | ||
| } | ||
| e.logger.Info().Uint64("height", state.LastBlockHeight). | ||
| Str("chain_id", state.ChainID).Msg("initialized state") | ||
| @@ -349,9 +356,18 @@ func (e *Executor) produceBlock() error { | ||
| } | ||
| // saved early for crash recovery, will be overwritten later with the final signature | ||
tac0turtle marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| if err = e.store.SaveBlockData(e.ctx, header, data, &types.Signature{}); err != nil { | ||
| b, err := e.store.NewBatch(context.Background()) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to create batch: %w", err) | ||
| } | ||
| if err = b.SaveBlockData(header, data, &types.Signature{}); err != nil { | ||
| return fmt.Errorf("failed to save block: %w", err) | ||
| } | ||
| if err := b.Commit(); err != nil { | ||
| return fmt.Errorf("failed to commit batch: %w", err) | ||
| } | ||
| } | ||
| newState, err := e.applyBlock(e.ctx, header.Header, data) | ||
| @@ -372,20 +388,27 @@ func (e *Executor) produceBlock() error { | ||
| return fmt.Errorf("failed to validate block: %w", err) | ||
| } | ||
| if err := e.store.SaveBlockData(e.ctx, header, data, &signature); err != nil { | ||
| batch, err := e.store.NewBatch(e.ctx) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to create batch: %w", err) | ||
| } | ||
| if err := batch.SaveBlockData(header, data, &signature); err != nil { | ||
| return fmt.Errorf("failed to save block: %w", err) | ||
| } | ||
| // Once the SaveBlockData has been saved we must update the height and the state. | ||
| // context.TODO() should be reverted to the real context (e.ctx) once https://github.com/evstack/ev-node/issues/2274 has been implemented, this prevents context cancellation | ||
| if err := e.store.SetHeight(context.TODO(), newHeight); err != nil { | ||
| if err := batch.SetHeight(newHeight); err != nil { | ||
| return fmt.Errorf("failed to update store height: %w", err) | ||
| } | ||
| if err := e.updateState(context.TODO(), newState); err != nil { | ||
| if err := e.updateState(batch, newState); err != nil { | ||
| return fmt.Errorf("failed to update state: %w", err) | ||
| } | ||
| if err := batch.Commit(); err != nil { | ||
| return fmt.Errorf("failed to commit block data: %w", err) | ||
| } | ||
| // broadcast header and data to P2P network | ||
| g, ctx := errgroup.WithContext(e.ctx) | ||
| g.Go(func() error { return e.headerBroadcaster.WriteToStoreAndBroadcast(ctx, header) }) | ||
| @@ -604,8 +627,8 @@ func (e *Executor) validateBlock(lastState types.State, header *types.SignedHead | ||
| } | ||
| // updateState saves the new state | ||
| func (e *Executor) updateState(ctx context.Context, newState types.State) error { | ||
| if err := e.store.UpdateState(ctx, newState); err != nil { | ||
| func (e *Executor) updateState(batch store.Batch, newState types.State) error { | ||
| if err := batch.UpdateState(newState); err != nil { | ||
| return err | ||
| } | ||
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
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.
Uh oh!
There was an error while loading. Please reload this page.