TimeMachine() creates a new StateMachine instance representing the blockchain state at a specified block height, allowing for a read-only view of the past state
(height uint64)
| 305 | |
| 306 | // TimeMachine() creates a new StateMachine instance representing the blockchain state at a specified block height, allowing for a read-only view of the past state |
| 307 | func (s *StateMachine) TimeMachine(height uint64) (*StateMachine, lib.ErrorI) { |
| 308 | // if height is zero, use the 'latest' height |
| 309 | if height == 0 || height > s.height { |
| 310 | height = s.height |
| 311 | } |
| 312 | // don't try to create a NewReadOnly with height 0 as it'll panic |
| 313 | if height == 0 { |
| 314 | // return the original state machine |
| 315 | return s, nil |
| 316 | } |
| 317 | // ensure the store is the proper type to allow historical views |
| 318 | store, ok := s.store.(lib.StoreI) |
| 319 | if !ok { |
| 320 | return nil, ErrWrongStoreType() |
| 321 | } |
| 322 | // create a NewReadOnly store at the specific height |
| 323 | heightStore, err := store.NewReadOnly(height) |
| 324 | if err != nil { |
| 325 | return nil, err |
| 326 | } |
| 327 | // initialize a new state machine |
| 328 | return New(s.Config, heightStore, s.Plugin, s.Metrics, s.log) |
| 329 | } |
| 330 | |
| 331 | // LoadCommittee() loads the committee validators for a particular committee at a particular height |
| 332 | func (s *StateMachine) LoadCommittee(chainId uint64, height uint64) (lib.ValidatorSet, lib.ErrorI) { |
no test coverage detected