Skip to content

Commit 9e6815f

Browse files
Merge remote-tracking branch 'origin/main' into issue-#151
2 parents 452fb4d + 96d7a33 commit 9e6815f

4 files changed

Lines changed: 22 additions & 15 deletions

File tree

cmd/rpc/admin.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,9 @@ func (s *Server) TransactionCloseOrder(w http.ResponseWriter, r *http.Request, _
369369
return nil, err
370370
}
371371
// Execute rpc call to the root chain
372+
s.rcManager.l.Lock()
372373
order, err := s.rcManager.GetOrder(rootChainId, 0, ptr.OrderId, s.config.ChainId)
374+
s.rcManager.l.Unlock()
373375
if err != nil {
374376
return nil, err
375377
}

cmd/rpc/query.go

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,39 +47,42 @@ func (s *Server) Height(w http.ResponseWriter, _ *http.Request, _ httprouter.Par
4747

4848
// Height response with the latest block
4949
func (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,

cmd/rpc/sock.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,6 @@ func (r *RCManager) GetLotteryWinner(rootChainId, height, id uint64) (*lib.Lotte
227227
// exit with the lottery winner
228228
return sub.Info.LotteryWinner, nil
229229
}
230-
// warn of the remote RPC call to the API of the 'root chain'
231-
r.log.Warnf("Executing remote Lottery call with requested height=%d and rootChainId=%d", height, rootChainId)
232230
// exit with the results of the remote RPC call to the API of the 'root chain'
233231
return sub.Lottery(height, id)
234232
}

lib/error.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ const (
254254
CodeSlashNonValidator ErrorCode = 90
255255
CodeEmptyOrderBook ErrorCode = 91
256256
CodeNoSubsidizedCommittees ErrorCode = 92
257+
CodeEmptyLotteryWinner ErrorCode = 93
257258

258259
// P2P Module
259260
P2PModule ErrorModule = "p2p"
@@ -776,5 +777,8 @@ func ErrStringToCommittee(s string) ErrorI {
776777

777778
func ErrNoSubsidizedCommittees(chainId uint64) ErrorI {
778779
return NewError(CodeNoSubsidizedCommittees, StateMachineModule, fmt.Sprintf("Chain ID %d has no subsidized committees", chainId))
780+
}
779781

782+
func ErrEmptyLotteryWinner() ErrorI {
783+
return NewError(CodeEmptyLotteryWinner, StateMachineModule, "Lottery winner is empty")
780784
}

0 commit comments

Comments
 (0)