LoadRootChainInfo() returns the 'need-to-know' information for a nested chain
(id, height uint64)
| 434 | |
| 435 | // LoadRootChainInfo() returns the 'need-to-know' information for a nested chain |
| 436 | func (s *StateMachine) LoadRootChainInfo(id, height uint64) (*lib.RootChainInfo, lib.ErrorI) { |
| 437 | defer lib.TimeTrack(s.log, time.Now(), 750*time.Millisecond) |
| 438 | lastHeight := uint64(1) |
| 439 | // update the metrics once complete |
| 440 | defer s.Metrics.UpdateGetRootChainInfo(time.Now()) |
| 441 | // if height is 0; use the latest height |
| 442 | if height == 0 { |
| 443 | height = s.height |
| 444 | } |
| 445 | // ensure lastHeight is not < 0 |
| 446 | if height != 1 { |
| 447 | lastHeight = height - 1 |
| 448 | } |
| 449 | // get the latest state machine |
| 450 | sm, err := s.TimeMachine(height) |
| 451 | if err != nil { |
| 452 | return nil, err |
| 453 | } |
| 454 | defer sm.Discard() |
| 455 | // get the previous state machine height |
| 456 | lastSM, err := s.TimeMachine(lastHeight) |
| 457 | if err != nil { |
| 458 | return nil, err |
| 459 | } |
| 460 | defer lastSM.Discard() |
| 461 | // get the committee |
| 462 | validatorSet, err := sm.GetCommitteeMembers(id) |
| 463 | if err != nil { |
| 464 | return nil, err |
| 465 | } |
| 466 | // get the n-1 committee |
| 467 | lvs, err := lastSM.GetCommitteeMembers(id) |
| 468 | if err != nil { |
| 469 | return nil, err |
| 470 | } |
| 471 | // get the delegate lottery winner |
| 472 | lotteryWinner, err := sm.LotteryWinner(id) |
| 473 | if err != nil { |
| 474 | return nil, err |
| 475 | } |
| 476 | // get the order book |
| 477 | orders, err := sm.GetOrderBook(id) |
| 478 | if err != nil { |
| 479 | return nil, err |
| 480 | } |
| 481 | // return the root chain info |
| 482 | return &lib.RootChainInfo{ |
| 483 | RootChainId: s.Config.ChainId, |
| 484 | Height: sm.height, |
| 485 | ValidatorSet: validatorSet.ValidatorSet, |
| 486 | LastValidatorSet: lvs.ValidatorSet, |
| 487 | LotteryWinner: lotteryWinner, |
| 488 | Orders: orders, |
| 489 | }, nil |
| 490 | } |
| 491 | |
| 492 | // Copy() makes a clone of the state machine |
| 493 | // this feature is used in mempool operation to be able to maintain a parallel ephemeral state without affecting the underlying state machine |
no test coverage detected