MCPcopy
hub / github.com/canopy-network/canopy / TimeMachine

Method TimeMachine

fsm/state.go:307–329  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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
307func (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
332func (s *StateMachine) LoadCommittee(chainId uint64, height uint64) (lib.ValidatorSet, lib.ErrorI) {

Callers 9

LoadLastProposersMethod · 0.95
LoadCommitteeDataMethod · 0.95
LoadCommitteeMethod · 0.95
LoadRootChainInfoMethod · 0.95
IndexerBlobMethod · 0.95
LoadRootChainIdMethod · 0.95
readOnlyStateMethod · 0.80

Calls 3

ErrWrongStoreTypeFunction · 0.85
NewFunction · 0.70
NewReadOnlyMethod · 0.65

Tested by

no test coverage detected