diff --git a/block/manager.go b/block/manager.go index 89b00b11a..afce8e161 100644 --- a/block/manager.go +++ b/block/manager.go @@ -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" @@ -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") } - 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") + } + 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") } + m.store.SetHeight(block.Header.Height) return isRequired, nil } diff --git a/state/executor.go b/state/executor.go index 028c3aadb..e40eedc73 100644 --- a/state/executor.go +++ b/state/executor.go @@ -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, @@ -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