Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions apis/eth_price.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import (
"bytes"
"encoding/json"
"fmt"
"github.com/golang/glog"
"github.com/montanaflynn/stats"
"io/ioutil"
"net/http"
"strconv"

"github.com/golang/glog"
"github.com/montanaflynn/stats"
)

type CoinbaseResponse struct {
Expand Down Expand Up @@ -194,7 +195,7 @@ func GetUSDToETHPrice() (float64, error) {
amount, err := getCoinbasePrice()
if err != nil {
// The amount will be zero in this case, which is fine
glog.Errorf("Error fetching Coinbase price: %v", err)
glog.V(2).Infof("Error fetching Coinbase price: %v", err)
}

if amount != 0 {
Expand All @@ -205,7 +206,7 @@ func GetUSDToETHPrice() (float64, error) {
amount, err := getCoingeckoPrice()
if err != nil {
// The amount will be zero in this case, which is fine
glog.Errorf("Error fetching Coingecko price: %v", err)
glog.V(2).Infof("Error fetching Coingecko price: %v", err)
}

if amount != 0 {
Expand All @@ -216,7 +217,7 @@ func GetUSDToETHPrice() (float64, error) {
amount, err := getBlockchainDotcomPrice()
if err != nil {
// The amount will be zero in this case, which is fine
glog.Errorf("Error fetching blockchain.com price: %v", err)
glog.V(2).Infof("Error fetching blockchain.com price: %v", err)
}

if amount != 0 {
Expand All @@ -227,7 +228,7 @@ func GetUSDToETHPrice() (float64, error) {
amount, err := getGeminiPrice()
if err != nil {
// The amount will be zero in this case, which is fine
glog.Errorf("Error fetching Gemini price: %v", err)
glog.V(2).Infof("Error fetching Gemini price: %v", err)
}

if amount != 0 {
Expand All @@ -238,7 +239,7 @@ func GetUSDToETHPrice() (float64, error) {
amount, err := getKrakenPrice()
if err != nil {
// The amount will be zero in this case, which is fine
glog.Errorf("Error fetching Kraken price: %v", err)
glog.V(2).Infof("Error fetching Kraken price: %v", err)
}

if amount != 0 {
Expand Down
2 changes: 1 addition & 1 deletion routes/admin_fees.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ func (fes *APIServer) GetTransactionFeeMapFromGlobalState() map[lib.TxnType][]*l
var feeOutputs []*lib.DeSoOutput
// Decode the bytes into the slice of DeSoOutputs
if err = gob.NewDecoder(bytes.NewReader(desoOutputBytes)).Decode(&feeOutputs); err != nil {
glog.Infof("Error decoding desoOutputBytes to slice of DeSoOutputs: %v - default to no additional fees", err)
glog.V(2).Infof("Error decoding desoOutputBytes to slice of DeSoOutputs: %v - default to no additional fees", err)
// Default to an empty slice.
transactionFeeMap[txnType] = []*lib.DeSoOutput{}
} else {
Expand Down
18 changes: 9 additions & 9 deletions routes/admin_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func (fes *APIServer) _handleNodeControlGetInfo(
existingDeSoPeers[currentPeerRes.IP+fmt.Sprintf(":%d", currentPeerRes.ProtocolPort)] = true
}
// Return some deso addrs from the addr manager.
desoAddrs := fes.backendServer.GetConnectionManager().GetAddrManager().AddressCache()
desoAddrs := fes.backendServer.AddrMgr.AddressCache()
sort.Slice(desoAddrs, func(ii, jj int) bool {
// Use a hash to get a random but deterministic ordering.
hashI := string(lib.Sha256DoubleHash([]byte(desoAddrs[ii].IP.String() + fmt.Sprintf(":%d", desoAddrs[ii].Port)))[:])
Expand Down Expand Up @@ -239,12 +239,12 @@ func (fes *APIServer) _handleConnectDeSoNode(
// increasing retry delay, but we should still clean it up at some point.
connectPeerDone := make(chan bool)
go func() {
netAddr, err := fes.backendServer.GetConnectionManager().GetAddrManager().HostToNetAddress(ip, protocolPort, 0)
netAddr, err := fes.backendServer.AddrMgr.HostToNetAddress(ip, protocolPort, 0)
if err != nil {
_AddBadRequestError(ww, fmt.Sprintf("_handleConnectDeSoNode: Cannot connect to node %s:%d: %v", ip, protocolPort, err))
return
}
fes.backendServer.GetConnectionManager().ConnectPeer(nil, netAddr)
fes.backendServer.GetNetworkManager().CreateNonValidatorOutboundConnection(ip)

// Spin until the peer shows up in the connection manager or until 100 iterations.
// Note the pause between each iteration.
Expand Down Expand Up @@ -274,7 +274,7 @@ func (fes *APIServer) _handleConnectDeSoNode(
// At this point the peer shoud be connected. Add their address to the addrmgr
// in case the user wants to connect again in the future. Set the source to be
// the address itself since we don't have anything else.
fes.backendServer.GetConnectionManager().GetAddrManager().AddAddress(netAddr, netAddr)
fes.backendServer.AddrMgr.AddAddress(netAddr, netAddr)

connectPeerDone <- true
return
Expand Down Expand Up @@ -320,13 +320,13 @@ func (fes *APIServer) _handleDisconnectDeSoNode(

// Manually remove the peer from the connection manager and mark it as such
// so that the connection manager won't reconnect to it or replace it.
fes.backendServer.GetConnectionManager().RemovePeer(peerFound)
peerFound.PeerManuallyRemovedFromConnectionManager = true

peerFound.Disconnect()
remoteNode := fes.backendServer.GetNetworkManager().GetRemoteNodeFromPeer(peerFound)
if remoteNode != nil {
fes.backendServer.GetNetworkManager().Disconnect(remoteNode)
}

res := NodeControlResponse{
// Return an empty response, which indicates we set the peer up to be connected.
// Return an empty response, which indicates we set the peer up to be disconnected.
}
if err := json.NewEncoder(ww).Encode(res); err != nil {
_AddBadRequestError(ww, fmt.Sprintf("NodeControl: Problem encoding response as JSON: %v", err))
Expand Down
2 changes: 1 addition & 1 deletion routes/admin_transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func TestUpdateGlobalParams(t *testing.T) {
require.Equal(t, globalParams.ValidatorJailEpochDuration, uint64(3))
require.Equal(t, globalParams.LeaderScheduleMaxNumValidators, uint64(100))
require.Equal(t, globalParams.EpochDurationNumBlocks, uint64(10))
require.Equal(t, globalParams.JailInactiveValidatorGracePeriodEpochs, uint64(48))
require.Equal(t, globalParams.JailInactiveValidatorGracePeriodEpochs, uint64(3))
}
{
// Update all GlobalParam fields.
Expand Down
10 changes: 5 additions & 5 deletions routes/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,14 @@ func (fes *APIServer) GetBlockchainDotComExchangeRate() (_exchangeRate float64,
url := "https://api.blockchain.com/v3/exchange/tickers/CLOUT-USD"
req, err := http.NewRequest("GET", url, nil)
if err != nil {
glog.Errorf("GetBlockchainDotComExchangeRate: Problem creating request: %v", err)
glog.V(2).Infof("GetBlockchainDotComExchangeRate: Problem creating request: %v", err)
continue
}
req.Header.Set("Content-Type", "application/json")

resp, err := httpClient.Do(req)
if err != nil {
glog.Errorf("GetBlockchainDotComExchangeRate: Problem with HTTP request %s: %v", url, err)
glog.V(2).Infof("GetBlockchainDotComExchangeRate: Problem with HTTP request %s: %v", url, err)
continue
}
defer resp.Body.Close()
Expand All @@ -167,7 +167,7 @@ func (fes *APIServer) GetBlockchainDotComExchangeRate() (_exchangeRate float64,
responseData := &BlockchainDeSoTickerResponse{}
decoder := json.NewDecoder(bytes.NewReader(body))
if err = decoder.Decode(responseData); err != nil {
glog.Errorf("GetBlockchainDotComExchangeRate: Problem decoding response JSON into "+
glog.V(2).Infof("GetBlockchainDotComExchangeRate: Problem decoding response JSON into "+
"interface %v, response: %v, error: %v", responseData, resp, err)
continue
}
Expand All @@ -179,13 +179,13 @@ func (fes *APIServer) GetBlockchainDotComExchangeRate() (_exchangeRate float64,
}
blockchainDotComExchangeRate, err := stats.Max(exchangeRatesFetched)
if err != nil {
glog.Errorf("GetBlockchainDotComExchangeRate: Problem getting max from list of float64s: %v", err)
glog.V(2).Infof("GetBlockchainDotComExchangeRate: Problem getting max from list of float64s: %v", err)
return 0, err
}
glog.V(2).Infof("Blockchain exchange rate: %v %v", blockchainDotComExchangeRate, exchangeRatesFetched)
if fes.backendServer != nil && fes.backendServer.GetStatsdClient() != nil {
if err = fes.backendServer.GetStatsdClient().Gauge("BLOCKCHAIN_LAST_TRADE_PRICE", blockchainDotComExchangeRate, []string{}, 1); err != nil {
glog.Errorf("GetBlockchainDotComExchangeRate: Error logging Last Trade Price of %f to datadog: %v", blockchainDotComExchangeRate, err)
glog.V(2).Infof("GetBlockchainDotComExchangeRate: Error logging Last Trade Price of %f to datadog: %v", blockchainDotComExchangeRate, err)
}
}
return blockchainDotComExchangeRate, nil
Expand Down
15 changes: 8 additions & 7 deletions routes/bitcoin_price.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import (
"bytes"
"encoding/json"
"fmt"
"github.com/golang/glog"
"github.com/montanaflynn/stats"
"io/ioutil"
"net/http"
"strconv"

"github.com/golang/glog"
"github.com/montanaflynn/stats"
)

type CoinbaseResponse struct {
Expand Down Expand Up @@ -206,7 +207,7 @@ func GetUSDToBTCPrice() (float64, error) {
amount, err := getCoinbasePrice()
if err != nil {
// The amount will be zero in this case, which is fine
glog.Errorf("Error fetching Coinbase price: %v", err)
glog.V(2).Infof("Error fetching Coinbase price: %v", err)
}

if amount != 0 {
Expand All @@ -217,7 +218,7 @@ func GetUSDToBTCPrice() (float64, error) {
amount, err := getCoingeckoPrice()
if err != nil {
// The amount will be zero in this case, which is fine
glog.Errorf("Error fetching Coingecko price: %v", err)
glog.V(2).Infof("Error fetching Coingecko price: %v", err)
}

if amount != 0 {
Expand All @@ -228,7 +229,7 @@ func GetUSDToBTCPrice() (float64, error) {
amount, err := getBlockchainDotcomPrice()
if err != nil {
// The amount will be zero in this case, which is fine
glog.Errorf("Error fetching blockchain.com price: %v", err)
glog.V(2).Infof("Error fetching blockchain.com price: %v", err)
}

if amount != 0 {
Expand All @@ -239,7 +240,7 @@ func GetUSDToBTCPrice() (float64, error) {
amount, err := getGeminiPrice()
if err != nil {
// The amount will be zero in this case, which is fine
glog.Errorf("Error fetching Gemini price: %v", err)
glog.V(2).Infof("Error fetching Gemini price: %v", err)
}

if amount != 0 {
Expand All @@ -250,7 +251,7 @@ func GetUSDToBTCPrice() (float64, error) {
amount, err := getKrakenPrice()
if err != nil {
// The amount will be zero in this case, which is fine
glog.Errorf("Error fetching Kraken price: %v", err)
glog.V(2).Infof("Error fetching Kraken price: %v", err)
}

if amount != 0 {
Expand Down
8 changes: 4 additions & 4 deletions routes/hot_feed.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ func (fes *APIServer) StartHotFeedRoutine() {

// The business.
func (fes *APIServer) UpdateHotFeed(resetCache bool) {
glog.Info("Refreshing hot feed...")
glog.V(2).Info("Refreshing hot feed...")
if resetCache {
glog.Info("Resetting hot feed cache.")
glog.V(2).Info("Resetting hot feed cache.")
fes.PostTagToPostHashesMap = make(map[string]map[lib.BlockHash]bool)
fes.PostHashToPostTagsMap = make(map[lib.BlockHash][]string)
fes.HotFeedBlockCache = make(map[lib.BlockHash]*lib.MsgDeSoBlock)
Expand All @@ -137,7 +137,7 @@ func (fes *APIServer) UpdateHotFeed(resetCache bool) {
// Replace the HotFeedApprovedPostsMap and HotFeedPKIDMultiplier map with the fresh ones.
fes.HotFeedApprovedPostsToMultipliers = hotFeedApprovedPosts
fes.HotFeedPKIDMultipliers = hotFeedPKIDMultipliers
glog.Infof("Updated hot feed maps")
glog.V(2).Infof("Updated hot feed maps")
}

func (fes *APIServer) UpdateHotFeedApprovedPostsMap(hotFeedApprovedPosts map[lib.BlockHash]float64) {
Expand Down Expand Up @@ -412,7 +412,7 @@ func (fes *APIServer) UpdateHotFeedOrderedList(
}

// Log how long this routine takes, since it could be heavy.
glog.Info("UpdateHotFeedOrderedList: Starting new update cycle.")
glog.V(2).Info("UpdateHotFeedOrderedList: Starting new update cycle.")
start := time.Now()

// Get a utxoView for lookups.
Expand Down
8 changes: 8 additions & 0 deletions routes/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ const (
RoutePathAppendExtraData = "/api/v0/append-extra-data"
RoutePathGetTransactionSpending = "/api/v0/get-transaction-spending"
RoutePathGetSignatureIndex = "/api/v0/signature-index"
RoutePathGetTxnConstructionParams = "/api/v0/txn-construction-params"

RoutePathGetUsersStateless = "/api/v0/get-users-stateless"
RoutePathDeleteIdentities = "/api/v0/delete-identities"
Expand Down Expand Up @@ -1024,6 +1025,13 @@ func (fes *APIServer) NewRouter() *muxtrace.Router {
fes.GetSignatureIndex,
PublicAccess,
},
{
"GetTxnConstructionParams",
[]string{"POST", "OPTIONS"},
RoutePathGetTxnConstructionParams,
fes.GetTxnConstructionParams,
PublicAccess,
},
{
"GetNotifications",
[]string{"POST", "OPTIONS"},
Expand Down
71 changes: 71 additions & 0 deletions routes/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -4198,3 +4198,74 @@ func (fes *APIServer) GetSignatureIndex(ww http.ResponseWriter, req *http.Reques
}
return
}

type GetTxnConstructionParamsRequest struct {
MinFeeRateNanosPerKB uint64
MempoolCongestionFactorBasisPoints uint64
MempoolPriorityPercentileBasisPoints uint64
PastBlocksCongestionFactorBasisPoints uint64
PastBlocksPriorityPercentileBasisPoints uint64
MaxBlockSize uint64
}

type GetTxnConstructionParamsResponse struct {
FeeRateNanosPerKB uint64
BlockHeight uint64
}

func (fes *APIServer) GetTxnConstructionParams(ww http.ResponseWriter, req *http.Request) {
decoder := json.NewDecoder(req.Body)
requestData := GetTxnConstructionParamsRequest{}
if err := decoder.Decode(&requestData); err != nil {
_AddBadRequestError(ww, "GetTxnConstructionParams: Problem parsing request body: "+err.Error())
return
}

// TODO: replace lib.MaxBasisPoints w/ a param defined by a flag from core.
mempoolCongestionFactorBasisPoints := requestData.MempoolCongestionFactorBasisPoints
if requestData.MempoolCongestionFactorBasisPoints == 0 {
mempoolCongestionFactorBasisPoints = lib.MaxBasisPoints
}

mempoolPriorityPercentileBasisPoints := requestData.MempoolPriorityPercentileBasisPoints
if requestData.MempoolPriorityPercentileBasisPoints == 0 {
mempoolPriorityPercentileBasisPoints = lib.MaxBasisPoints
}

pastBlocksCongestionFactorBasisPoints := requestData.PastBlocksCongestionFactorBasisPoints
if requestData.PastBlocksCongestionFactorBasisPoints == 0 {
pastBlocksCongestionFactorBasisPoints = lib.MaxBasisPoints
}

pastBlocksPriorityPercentileBasisPoints := requestData.PastBlocksPriorityPercentileBasisPoints
if requestData.PastBlocksPriorityPercentileBasisPoints == 0 {
pastBlocksPriorityPercentileBasisPoints = lib.MaxBasisPoints
}

maxBlockSize := requestData.MaxBlockSize
if requestData.MaxBlockSize == 0 {
maxBlockSize = fes.Params.MaxBlockSizeBytes
}

// Get the fees from the mempool
feeRate, err := fes.backendServer.GetMempool().EstimateFeeRate(
requestData.MinFeeRateNanosPerKB,
mempoolCongestionFactorBasisPoints,
mempoolPriorityPercentileBasisPoints,
pastBlocksCongestionFactorBasisPoints,
pastBlocksPriorityPercentileBasisPoints,
maxBlockSize,
)
if err != nil {
_AddBadRequestError(ww, "GetTxnConstructionParams: Problem getting fees: "+err.Error())
return
}
// Return the fees
if err = json.NewEncoder(ww).Encode(GetTxnConstructionParamsResponse{
FeeRateNanosPerKB: feeRate,
BlockHeight: uint64(fes.backendServer.GetBlockchain().BlockTip().Height),
}); err != nil {
_AddBadRequestError(ww, "GetTxnConstructionParams: Problem encoding response as JSON: "+err.Error())
return
}
}
6 changes: 6 additions & 0 deletions routes/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -1469,6 +1469,9 @@ func (fes *APIServer) SetJumioUSDCents() {
glog.Errorf("SetJumioUSDCents: Error getting Jumio USD Cents from global state: %v", err)
return
}
if len(val) == 0 {
return
}
jumioUSDCents, bytesRead := lib.Uvarint(val)
if bytesRead <= 0 {
glog.Errorf("SetJumioUSDCents: invalid bytes read: %v", bytesRead)
Expand All @@ -1487,6 +1490,9 @@ func (fes *APIServer) SetJumioKickbackUSDCents() {
glog.Errorf("SetJumioKickbackUSDCents: Error getting Jumio Kickback USD Cents from global state: %v", err)
return
}
if len(val) == 0 {
return
}
jumioKickbackUSDCents, bytesRead := lib.Uvarint(val)
if bytesRead <= 0 {
glog.Errorf("SetJumioKickbackUSDCents: invalid bytes read: %v", bytesRead)
Expand Down
Loading