Skip to content

Commit

Permalink
feat(rollback): add rollback support (#1300)
Browse files Browse the repository at this point in the history
  • Loading branch information
srene authored and danwt committed Jan 9, 2025
1 parent 5bb1121 commit d6562d6
Show file tree
Hide file tree
Showing 21 changed files with 171 additions and 111 deletions.
4 changes: 2 additions & 2 deletions block/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (m *Manager) applyBlock(block *types.Block, commit *types.Commit, blockMeta
// In case the following true, it means we crashed after the app commit but before updating the state
// In that case we'll want to align the state with the app commit result, as if the block was applied.
if isBlockAlreadyApplied {
err := m.UpdateStateFromApp(block.Header.Hash())
err := m.UpdateStateFromApp(block)
if err != nil {
return fmt.Errorf("update state from app: %w", err)
}
Expand Down Expand Up @@ -125,7 +125,7 @@ func (m *Manager) applyBlock(block *types.Block, commit *types.Commit, blockMeta
}
// Update the state with the new app hash, and store height from the commit.
// Every one of those, if happens before commit, prevents us from re-executing the block in case failed during commit.
m.Executor.UpdateStateAfterCommit(m.State, responses, appHash, block.Header.Height, block.Header.Hash())
m.Executor.UpdateStateAfterCommit(m.State, responses, appHash, block)

}

Expand Down
2 changes: 1 addition & 1 deletion block/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type ExecutorI interface {
ExecuteBlock(block *types.Block) (*tmstate.ABCIResponses, error)
UpdateStateAfterInitChain(s *types.State, res *abci.ResponseInitChain)
UpdateMempoolAfterInitChain(s *types.State)
UpdateStateAfterCommit(s *types.State, resp *tmstate.ABCIResponses, appHash []byte, height uint64, lastHeaderHash [32]byte)
UpdateStateAfterCommit(s *types.State, resp *tmstate.ABCIResponses, appHash []byte, block *types.Block)
UpdateProposerFromBlock(s *types.State, seqSet *types.SequencerSet, block *types.Block) bool

/* Consensus Messages */
Expand Down
4 changes: 2 additions & 2 deletions block/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ func TestApplyBlock(t *testing.T) {
require.NotNil(resp)
appHash, _, err := executor.Commit(state, block, resp)
require.NoError(err)
executor.UpdateStateAfterCommit(state, resp, appHash, block.Header.Height, block.Header.Hash())
executor.UpdateStateAfterCommit(state, resp, appHash, block)
assert.Equal(uint64(1), state.Height())
assert.Equal(mockAppHash, state.AppHash)

Expand Down Expand Up @@ -390,7 +390,7 @@ func TestApplyBlock(t *testing.T) {
require.NotNil(resp)
_, _, err = executor.Commit(state, block, resp)
require.NoError(err)
executor.UpdateStateAfterCommit(state, resp, appHash, block.Header.Height, block.Header.Hash())
executor.UpdateStateAfterCommit(state, resp, appHash, block)
assert.Equal(uint64(2), state.Height())

// check rollapp params update
Expand Down
12 changes: 6 additions & 6 deletions block/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,6 @@ func NewManager(
return nil, err
}

// update dymint state with next revision info
err = m.updateStateForNextRevision()
if err != nil {
return nil, err
}

// validate configuration params and rollapp consensus params are in line
err = m.ValidateConfigWithRollappParams()
if err != nil {
Expand All @@ -222,6 +216,12 @@ func (m *Manager) Start(ctx context.Context) error {
}
}

// update dymint state with next revision info
err := m.updateStateForNextRevision()
if err != nil {
return err
}

// Check if a proposer on the rollapp is set. In case no proposer is set on the Rollapp, fallback to the hub proposer (If such exists).
// No proposer on the rollapp means that at some point there was no available proposer.
// In case there is also no proposer on the hub to our current height, it means that the chain is halted.
Expand Down
9 changes: 5 additions & 4 deletions block/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func NewStateFromGenesis(genDoc *tmtypes.GenesisDoc) (*types.State, error) {
}

// UpdateStateFromApp is responsible for aligning the state of the store from the abci app
func (m *Manager) UpdateStateFromApp(blockHeaderHash [32]byte) error {
func (m *Manager) UpdateStateFromApp(block *types.Block) error {
proxyAppInfo, err := m.Executor.GetAppInfo()
if err != nil {
return errorsmod.Wrap(err, "get app info")
Expand All @@ -87,7 +87,7 @@ func (m *Manager) UpdateStateFromApp(blockHeaderHash [32]byte) error {
}

// update the state with the app hashes created on the app commit
m.Executor.UpdateStateAfterCommit(m.State, resp, proxyAppInfo.LastBlockAppHash, appHeight, blockHeaderHash)
m.Executor.UpdateStateAfterCommit(m.State, resp, proxyAppInfo.LastBlockAppHash, block)

return nil
}
Expand Down Expand Up @@ -116,12 +116,13 @@ func (e *Executor) UpdateMempoolAfterInitChain(s *types.State) {
}

// UpdateStateAfterCommit updates the state with the app hash and last results hash
func (e *Executor) UpdateStateAfterCommit(s *types.State, resp *tmstate.ABCIResponses, appHash []byte, height uint64, lastHeaderHash [32]byte) {
func (e *Executor) UpdateStateAfterCommit(s *types.State, resp *tmstate.ABCIResponses, appHash []byte, block *types.Block) {
copy(s.AppHash[:], appHash[:])
copy(s.LastResultsHash[:], tmtypes.NewResults(resp.DeliverTxs).Hash())
lastHeaderHash := block.Header.Hash()
copy(s.LastHeaderHash[:], lastHeaderHash[:])

s.SetHeight(height)
s.SetHeight(block.Header.Height)
if resp.EndBlock.ConsensusParamUpdates != nil {
s.ConsensusParams.Block.MaxGas = resp.EndBlock.ConsensusParamUpdates.Block.MaxGas
s.ConsensusParams.Block.MaxBytes = resp.EndBlock.ConsensusParamUpdates.Block.MaxBytes
Expand Down
33 changes: 16 additions & 17 deletions mocks/github.com/dymensionxyz/dymint/block/mock_ExecutorI.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 11 additions & 11 deletions mocks/github.com/dymensionxyz/dymint/da/avail/mock_SubstrateApiI.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d6562d6

Please sign in to comment.