@@ -47,39 +47,42 @@ func (s *Server) Height(w http.ResponseWriter, _ *http.Request, _ httprouter.Par
4747
4848// Height response with the latest block
4949func (s * Server ) EcoParameters (w http.ResponseWriter , r * http.Request , _ httprouter.Params ) {
50- // Unmarshal the requested chain id
50+ // unmarshal the requested chain id
5151 post := new (chainRequest )
5252 if ok := unmarshal (w , r , post ); ! ok {
5353 return
5454 }
55- // Create a read-only state for the latest block and determine economic parameters
55+ // create a read-only state for the latest block and determine economic parameters
5656 s .readOnlyState (0 , func (state * fsm.StateMachine ) lib.ErrorI {
57- // Get the lottery winner
58- delegate , err := s .controller .GetRootChainLotteryWinner (state .Height ())
59- // if an error occurred
57+ // get the root id
58+ rootChainId , err := state .GetRootChainId ()
6059 if err != nil {
6160 return err
6261 }
63-
64- // Get the root id
65- rootChainId , err := state .GetRootChainId ()
62+ // get the lottery winner
63+ s .rcManager .l .Lock ()
64+ delegate , err := s .rcManager .GetLotteryWinner (rootChainId , 0 , s .config .ChainId )
65+ s .rcManager .l .Unlock ()
66+ // if an error occurred
6667 if err != nil {
6768 return err
6869 }
69- // Find proposer cut
70- proposerCut := uint64 (100 - delegate .Cut )
71- // Remove sub-validator and sub-delegate cuts if requested chain id is non-root id
70+ // ensure non-nil delegate
71+ if delegate == nil {
72+ return lib .ErrEmptyLotteryWinner ()
73+ }
74+ // find proposer cut
75+ proposerCut := 100 - delegate .Cut
76+ // remove sub-validator and sub-delegate cuts if requested chain id is non-root id
7277 if post .ChainId != rootChainId {
7378 proposerCut -= delegate .Cut // sub-validator
7479 proposerCut -= delegate .Cut // sub-delegate
7580 }
76-
7781 daoCut , totalMint , committeeMint , err := state .GetBlockMintStats (post .ChainId )
7882 if err != nil {
7983 write (w , err .Error (), http .StatusBadRequest )
8084 return nil
8185 }
82-
8386 write (w , economicParameterResponse {
8487 DAOCut : daoCut ,
8588 MintPerBlock : totalMint ,
0 commit comments