Skip to content

Commit

Permalink
Add locks to State; Export LoadValidators func
Browse files Browse the repository at this point in the history
  • Loading branch information
danil-lashin committed Feb 11, 2020
1 parent d035182 commit 95e1509
Show file tree
Hide file tree
Showing 18 changed files with 60 additions and 325 deletions.
3 changes: 3 additions & 0 deletions api/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ func Address(address types.Address, height int) (*AddressResponse, error) {
return nil, err
}

cState.Lock()
defer cState.Unlock()

response := AddressResponse{
Balance: make(map[string]string),
TransactionCount: cState.Accounts.GetNonce(address),
Expand Down
3 changes: 3 additions & 0 deletions api/addresses.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ func Addresses(addresses []types.Address, height int) (*[]AddressesResponse, err
return nil, err
}

cState.Lock()
defer cState.Unlock()

response := make([]AddressesResponse, len(addresses))

for i, address := range addresses {
Expand Down
3 changes: 3 additions & 0 deletions api/candidate.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ func Candidate(pubkey types.Pubkey, height int) (*CandidateResponse, error) {
return nil, err
}

cState.Lock()
defer cState.Unlock()

if height != 0 {
cState.Candidates.LoadCandidates()
cState.Candidates.LoadStakes()
Expand Down
3 changes: 3 additions & 0 deletions api/candidates.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ func Candidates(height int, includeStakes bool) (*[]CandidateResponse, error) {
return nil, err
}

cState.Lock()
defer cState.Unlock()

if height != 0 {
cState.Candidates.LoadCandidates()
if includeStakes {
Expand Down
3 changes: 3 additions & 0 deletions api/coin_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ func CoinInfo(coinSymbol string, height int) (*CoinInfoResponse, error) {
return nil, err
}

cState.Lock()
defer cState.Unlock()

coin := cState.Coins.GetCoin(types.StrToCoinSymbol(coinSymbol))
if coin == nil {
return nil, rpctypes.RPCError{Code: 404, Message: "Coin not found"}
Expand Down
3 changes: 3 additions & 0 deletions api/estimate_coin_buy.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ func EstimateCoinBuy(coinToSellString string, coinToBuyString string, valueToBuy
return nil, err
}

cState.Lock()
defer cState.Unlock()

coinToSell := types.StrToCoinSymbol(coinToSellString)
coinToBuy := types.StrToCoinSymbol(coinToBuyString)

Expand Down
3 changes: 3 additions & 0 deletions api/estimate_coin_sell.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ func EstimateCoinSell(
return nil, err
}

cState.Lock()
defer cState.Unlock()

coinToSell := types.StrToCoinSymbol(coinToSellString)
coinToBuy := types.StrToCoinSymbol(coinToBuyString)

Expand Down
3 changes: 3 additions & 0 deletions api/estimate_coin_sell_all.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ func EstimateCoinSellAll(
return nil, err
}

cState.Lock()
defer cState.Unlock()

if gasPrice < 1 {
gasPrice = 1
}
Expand Down
3 changes: 3 additions & 0 deletions api/estimate_tx_commission.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ func EstimateTxCommission(tx []byte, height int) (*TxCommissionResponse, error)
return nil, err
}

cState.Lock()
defer cState.Unlock()

decodedTx, err := transaction.TxDecoder.DecodeFromBytes(tx)
if err != nil {
return nil, rpctypes.RPCError{Code: 400, Message: "Cannot decode transaction", Data: err.Error()}
Expand Down
3 changes: 3 additions & 0 deletions api/maxgas.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ func MaxGas(height int) (*uint64, error) {
return nil, err
}

cState.Lock()
defer cState.Unlock()

maxGas := cState.App.GetMaxGas()
return &maxGas, nil
}
5 changes: 5 additions & 0 deletions api/missed_blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ func MissedBlocks(pubkey types.Pubkey, height int) (*MissedBlocksResponse, error
return nil, err
}

cState.Lock()
defer cState.Unlock()

cState.Validators.LoadValidators()

vals := cState.Validators.GetValidators()
if vals == nil {
return nil, rpctypes.RPCError{Code: 404, Message: "Validators not found"}
Expand Down
91 changes: 0 additions & 91 deletions cmd/export/main.go

This file was deleted.

8 changes: 0 additions & 8 deletions cmd/export/readme.md

This file was deleted.

Loading

0 comments on commit 95e1509

Please sign in to comment.