@@ -222,10 +222,24 @@ func (s *DefaultStore) GetState(ctx context.Context) (types.State, error) {
222222func (s * DefaultStore ) GetStateAtHeight (ctx context.Context , height uint64 ) (types.State , error ) {
223223 blob , err := s .db .Get (ctx , ds .NewKey (getStateAtHeightKey (height )))
224224 if err != nil {
225- if errors .Is (err , ds .ErrNotFound ) {
225+ currentHeight , err := s .Height (ctx )
226+ if err != nil {
227+ return types.State {}, fmt .Errorf ("failed to retrieve current height: %w" , err )
228+ }
229+
230+ // prior to https://github.com/evstack/ev-node/pull/2499 only the last state was stored in the state key
231+ if currentHeight == height + 1 {
232+ blob , err = s .db .Get (ctx , ds .NewKey (statePrefix ))
233+ if errors .Is (err , ds .ErrNotFound ) {
234+ return types.State {}, fmt .Errorf ("no state found at height %d" , height )
235+ } else if err != nil {
236+ return types.State {}, fmt .Errorf ("failed to retrieve state at height %d: %w" , height , err )
237+ }
238+ } else if errors .Is (err , ds .ErrNotFound ) {
226239 return types.State {}, fmt .Errorf ("no state found at height %d" , height )
240+ } else {
241+ return types.State {}, fmt .Errorf ("failed to retrieve state at height %d: %w" , height , err )
227242 }
228- return types.State {}, fmt .Errorf ("failed to retrieve state at height %d: %w" , height , err )
229243 }
230244
231245 var pbState pb.State
0 commit comments