Skip to content

Commit

Permalink
fixed initialization of new state in BlockExecutor updateState
Browse files Browse the repository at this point in the history
  • Loading branch information
mtsitrin committed Jun 27, 2023
1 parent 3ba9353 commit 8f17317
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 19 deletions.
39 changes: 20 additions & 19 deletions block/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (

"code.cloudfoundry.org/go-diodes"

"cosmossdk.io/errors"
"github.com/avast/retry-go"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
"github.com/cosmos/cosmos-sdk/types/errors"
abciconv "github.com/dymensionxyz/dymint/conv/abci"
"github.com/dymensionxyz/dymint/node/events"
"github.com/dymensionxyz/dymint/p2p"
Expand Down Expand Up @@ -567,27 +567,28 @@ func (m *Manager) alignStoreWithApp(ctx context.Context, block *types.Block) (bo
if err != nil {
return isRequired, errors.Wrap(err, "failed to get app info")
}

Check warning on line 569 in block/manager.go

View check run for this annotation

Codecov / codecov/patch

block/manager.go#L568-L569

Added lines #L568 - L569 were not covered by tests
if uint64(proxyAppInfo.LastBlockHeight) == block.Header.Height {
isRequired = true
m.logger.Info("Skipping block application and only updating store height and state hash", "height", block.Header.Height)
// update the state with the hash, last store height and last validators.
m.lastState.AppHash = *(*[32]byte)(proxyAppInfo.LastBlockAppHash)
m.lastState.LastStoreHeight = block.Header.Height
m.lastState.LastValidators = m.lastState.Validators.Copy()
if uint64(proxyAppInfo.LastBlockHeight) != block.Header.Height {
return isRequired, nil
}

resp, err := m.store.LoadBlockResponses(block.Header.Height)
if err != nil {
return isRequired, errors.Wrap(err, "failed to load block responses")
}
copy(m.lastState.LastResultsHash[:], tmtypes.NewResults(resp.DeliverTxs).Hash())
isRequired = true
m.logger.Info("Skipping block application and only updating store height and state hash", "height", block.Header.Height)
// update the state with the hash, last store height and last validators.
m.lastState.AppHash = *(*[32]byte)(proxyAppInfo.LastBlockAppHash)
m.lastState.LastStoreHeight = block.Header.Height
m.lastState.LastValidators = m.lastState.Validators.Copy()

_, err = m.store.UpdateState(m.lastState, nil)
if err != nil {
return isRequired, errors.Wrap(err, "failed to update state")
}
m.store.SetHeight(block.Header.Height)
return isRequired, nil
resp, err := m.store.LoadBlockResponses(block.Header.Height)
if err != nil {
return isRequired, errors.Wrap(err, "failed to load block responses")
}

Check warning on line 584 in block/manager.go

View check run for this annotation

Codecov / codecov/patch

block/manager.go#L583-L584

Added lines #L583 - L584 were not covered by tests
copy(m.lastState.LastResultsHash[:], tmtypes.NewResults(resp.DeliverTxs).Hash())

_, err = m.store.UpdateState(m.lastState, nil)
if err != nil {
return isRequired, errors.Wrap(err, "failed to update state")
}

Check warning on line 590 in block/manager.go

View check run for this annotation

Codecov / codecov/patch

block/manager.go#L589-L590

Added lines #L589 - L590 were not covered by tests
m.store.SetHeight(block.Header.Height)
return isRequired, nil
}

Expand Down
4 changes: 4 additions & 0 deletions state/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ func (e *BlockExecutor) updateState(state types.State, block *types.Block, abciR
}

hash := block.Header.Hash()
//TODO: we can probably pass the state as a pointer and update it directly
s := types.State{
Version: state.Version,
ChainID: state.ChainID,
Expand All @@ -224,6 +225,9 @@ func (e *BlockExecutor) updateState(state types.State, block *types.Block, abciR
AppHash: state.AppHash,
LastValidators: state.LastValidators.Copy(),
LastStoreHeight: state.LastStoreHeight,

LastResultsHash: state.LastResultsHash,
BaseHeight: state.BaseHeight,
}

return s, nil
Expand Down

0 comments on commit 8f17317

Please sign in to comment.