Skip to content
This repository has been archived by the owner on Jan 16, 2024. It is now read-only.

Commit

Permalink
Remove priceupdater (#1053)
Browse files Browse the repository at this point in the history
* remove priceupdater

* remove update and create fiat

* remove config price updater
  • Loading branch information
ARR552 authored Aug 13, 2021
1 parent 2706980 commit b01d1b4
Show file tree
Hide file tree
Showing 11 changed files with 6 additions and 825 deletions.
3 changes: 0 additions & 3 deletions SETUP_NODE.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,6 @@ folder.
Is so that the API can be accessed by users outside the host.
- [ ] Add APIKey to `PriceUpdater.Fiat` section.
Get a key [here](https://exchangeratesapi.io/)
- [ ] Change PostgreSQL section with the values of user created before.
- HostWrite: Use the IP from server instead of localhost
Expand Down
5 changes: 4 additions & 1 deletion api/fiat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ import (
)

func genFiatPrices(db *historydb.HistoryDB) error {
err := db.CreateFiatPrice("EUR", "USD", 0.82)
_, err := db.DB().Exec(
"INSERT INTO fiat(currency, base_currency, price) VALUES ($1, $2, $3);",
"EUR", "USD", 0.82,
)
if err != nil {
return err
}
Expand Down
50 changes: 0 additions & 50 deletions cmd/heznode/cfg.builder.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,56 +12,6 @@
### Maximum amount of time that an API request can wait to establish a SQL connection
#SQLConnectionTimeout = "2s"

#[PriceUpdater]
### Interval between price updater calls
#Interval = "60s"
### Priority order to use the different providers
#Priority = "bitfinexV2,CoinGeckoV3"
### Static price for tokens
#Statictokens="" # <tokenId>=<forced_price>,<tokenId>=<forced_price>

#[PriceUpdater.Fiat]
### This parameter allow access to the external service
#APIKey=""
### Url of the external service
#URL="https://api.exchangeratesapi.io/v1/"
### Base currency used to get prices
#BaseCurrency="USD"
### Currencies that the hermez node is going to store
#Currencies="CNY,EUR,JPY,GBP"

#[[PriceUpdater.Provider]]
### Provider name used in "Priority" field
#Provider = "bitfinexV2"
### Provider api base url
#BASEURL = "https://api-pub.bitfinex.com/v2/"
### Provider url
#URL = "ticker/t"
### Second part of the url
#URLExtraParams = "USD"
### Available update methods:
### - ignore method don't update the price leave it as it is on the DB. Type ignore or leave the field empty
### - static method is performed writing the price in Statictokens.
### Example: Symbols = "0=ETH,1=HEZ,2=ignore,4=DAI,5=WBT,6=static,7=XAUT:,8=UNI,9=SUSHI:,10=COMP:,11=,12=AAVE:,13=YFI,14=LINK:"
### Symbols that the price updater should use in order to get the prices successfully
#Symbols = "0=ETH,2=UST,8=ignore,9=SUSHI:,5=WBT,14=LINK:,12=AAVE:,7=XAUT:,10=COMP:,6=ETH"

#[[PriceUpdater.Provider]]
### Provider name used in "Priority" field
#Provider = "CoinGeckoV3"
### Provider api base url
#BASEURL = "https://api.coingecko.com/api/v3/"
### Provider url
#URL = "simple/token_price/ethereum?contract_addresses="
### Second part of the url
#URLExtraParams = "&vs_currencies=usd"
### Available update methods:
### - ignore method don't update the price leave it as it is on the DB. Type ignore or leave the field empty
### - static method is performed writing the price in Statictokens.
### Example: Addresses="0=0x00,1=0x12,2=0x12,4=0x12,5=0x12,6=,7=0x12,8=,9=0x12,10=0x12,11=ignore,12=0x12,13=0x12,14=0x12"
### Addresses that the price updater should use in order to get the prices successfully
#Addresses="0=0x0000000000000000000000000000000000000000,2=0xdac17f958d2ee523a2206206994597c13d831ec7,8=ignore"

#[Debug]
### If it is set, the debug api will listen in this address and port
#APIAddress = "0.0.0.0:12345"
Expand Down
32 changes: 0 additions & 32 deletions config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,6 @@ UpdateRecommendedFeeInterval = HEZNODE_API_UPDATERECOMMENDEDFEEINTERVAL
MaxSQLConnections = HEZNODE_API_MAXSQLCONNECTIONS
SQLConnectionTimeout = HEZNODE_API_SQLCONNECTIONTIMEOUT
[PriceUpdater]
Interval = HEZNODE_PRICEUPDATER_INTERVAL
Priority = HEZNODE_PRICEUPDATER_PRIORITY
Statictokens = HEZNODE_PRICEUPDATER_STATICTOKENS
[PriceUpdater.Fiat]
APIKey = HEZNODE_PRICEUPDATER_FIAT_APIKEY
URL = HEZNODE_PRICEUPDATER_FIAT_URL
BaseCurrency = HEZNODE_PRICEUPDATER_FIAT_BASECURRENCY
Currencies = HEZNODE_PRICEUPDATER_FIAT_CURRENCIES
[[PriceUpdater.Provider]]
Provider = HEZNODE_PRICEUPDATER_PROVIDER_PROVIDER
BASEURL = HEZNODE_PRICEUPDATER_PROVIDER_BASEURL
URL = HEZNODE_PRICEUPDATER_PROVIDER_URL
URLExtraParams = HEZNODE_PRICEUPDATER_PROVIDER_URLEXTRAPARAMS
Symbols = HEZNODE_PRICEUPDATER_PROVIDER_SYMBOLS
Addresses = HEZNODE_PRICEUPDATER_PROVIDER_ADDRESSES
[Debug]
APIAddress = HEZNODE_DEBUG_APIADDRESS
MeddlerLogs = HEZNODE_DEBUG_MEDDLERLOGS
Expand Down Expand Up @@ -154,19 +135,6 @@ StaticValue = HEZNODE_RECOMMENDEDFEEPOLICY_STATICVALUE
|API|UpdateRecommendedFeeInterval|HEZNODE_API_UPDATERECOMMENDEDFEEINTERVAL|Optional|"10s"|Interval between updates of the recommended fees
|API|MaxSQLConnections|HEZNODE_API_MAXSQLCONNECTIONS|Optional|100|Maximum concurrent connections allowed between API and SQL
|API|SQLConnectionTimeout|HEZNODE_API_SQLCONNECTIONTIMEOUT|Optional|"2s"|Maximum amount of time that an API request can wait to establish a SQL connection
|PriceUpdater|Interval|HEZNODE_PRICEUPDATER_INTERVAL|Optional|"60s"|Interval between price updater calls
|PriceUpdater|Priority|HEZNODE_PRICEUPDATER_PRIORITY|Optional|"bitfinexV2,CoinGeckoV3"|Priority order to use the different providers
|PriceUpdater|Statictokens|HEZNODE_PRICEUPDATER_STATICTOKENS|Optional|""|Static price for tokens
|PriceUpdater.Fiat|APIKey|HEZNODE_PRICEUPDATER_FIAT_APIKEY|Optional|""|This parameter allow access to the external service
|PriceUpdater.Fiat|URL|HEZNODE_PRICEUPDATER_FIAT_URL|Optional|"https://api.exchangeratesapi.io/v1/"|Url of the external service
|PriceUpdater.Fiat|BaseCurrency|HEZNODE_PRICEUPDATER_FIAT_BASECURRENCY|Optional|"USD"|Base currency used to get prices
|PriceUpdater.Fiat|Currencies|HEZNODE_PRICEUPDATER_FIAT_CURRENCIES|Optional|"CNY,EUR,JPY,GBP"|Currencies that the hermez node is going to store
|PriceUpdater.Provider|Provider|HEZNODE_PRICEUPDATER_PROVIDER_PROVIDER|Optional|"bitfinexV2"|Provider name used in "Priority" field
|PriceUpdater.Provider|BASEURL|HEZNODE_PRICEUPDATER_PROVIDER_BASEURL|Optional|"https://api-pub.bitfinex.com/v2/"|Provider api base url
|PriceUpdater.Provider|URL|HEZNODE_PRICEUPDATER_PROVIDER_URL|Optional|"ticker/t"| Provider url
|PriceUpdater.Provider|URLExtraParams|HEZNODE_PRICEUPDATER_PROVIDER_URLEXTRAPARAMS|Optional|"USD"|Second part of the url
|PriceUpdater.Provider|Symbols|HEZNODE_PRICEUPDATER_PROVIDER_SYMBOLS|Optional|"2=UST,3=UDC,5=WBT,7=XAUT:,9=SUSHI:,10=COMP:,12=AAVE:,14=LINK:,24=GNT,27=ignore,28=ignore,29=ignore,30=ignore,31=ignore,32=ignore"|Symbols that the price updater should use in order to get the prices successfully
|PriceUpdater.Provider|Addresses|HEZNODE_PRICEUPDATER_PROVIDER_ADDRESSES|Optional|Addresses="6=0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,17=0xde30da39c46104798bb5aa3fe8b9e0e1f348163f,18=0x7d1afa7b718fb893db30a3abc0cfc608aacfebb0,21=0xc944e90c64b2c07662a292be6244bdf05cda44a7,26=0xD533a949740bb3306d119CC777fa900bA034cd52,27=ignore,28=ignore,29=ignore,30=ignore,31=ignore,32=ignore"|Addresses that the price updater should use in order to get the prices successfully
|Debug|APIAddress|HEZNODE_DEBUG_APIADDRESS|Optional|"0.0.0.0:12345"|If it is set, the debug api will listen in this address and port
|Debug|MeddlerLogs|HEZNODE_DEBUG_MEDDLERLOGS|Optional|true|Enables meddler debug mode, where unused columns and struct fields will be logged
|Debug|GinDebugMode|HEZNODE_DEBUG_GINDEBUGMODE|Optional|false|Sets the web framework Gin-Gonic to run in debug mode
Expand Down
41 changes: 0 additions & 41 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package config
import (
"fmt"
"math/big"
"os"
"strings"
"time"

Expand All @@ -12,7 +11,6 @@ import (
"github.com/hermeznetwork/hermez-node/api/stateapiupdater"
"github.com/hermeznetwork/hermez-node/common"
"github.com/hermeznetwork/hermez-node/log"
"github.com/hermeznetwork/hermez-node/priceupdater"
"github.com/hermeznetwork/tracerr"
"github.com/iden3/go-iden3-crypto/babyjub"
"gopkg.in/go-playground/validator.v9"
Expand Down Expand Up @@ -287,18 +285,6 @@ type NodeDebug struct {

// Node is the hermez node configuration.
type Node struct {
PriceUpdater struct {
// Interval between price updater calls
Interval Duration `validate:"required" env:"HEZNODE_PRICEUPDATER_INTERVAL"`
// Priority option defines the priority provider
Priority string `validate:"required" env:"HEZNODE_PRICEUPDATER_PRIORITY"`
// TokensConfig to specify how each token get it's price updated
Provider []priceupdater.Provider
// Statictokens defines the static prices for tokens
Statictokens string `env:"HEZNODE_PRICEUPDATER_STATICTOKENS"`
// Fiat defines the prices for fiat currencies
Fiat priceupdater.Fiat
} `validate:"required"`
StateDB struct {
// Path where the synchronizer StateDB is stored
Path string `validate:"required" env:"HEZNODE_STATEDB_PATH"`
Expand Down Expand Up @@ -406,33 +392,7 @@ func LoadNode(path string, coordinator bool) (*Node, error) {
}
log.Warn(err.Error())
}
//Get env arrays
//Price Updater
if os.Getenv("HEZNODE_PRICEUPDATER_PROVIDER_PROVIDER") != "" {
provider := priceupdater.Provider{
Provider: os.Getenv("HEZNODE_PRICEUPDATER_PROVIDER_PROVIDER"),
}
if os.Getenv("HEZNODE_PRICEUPDATER_PROVIDER_BASEURL") != "" {
provider.BaseURL = os.Getenv("HEZNODE_PRICEUPDATER_PROVIDER_BASEURL")
}
if os.Getenv("HEZNODE_PRICEUPDATER_PROVIDER_URL") != "" {
provider.URL = os.Getenv("HEZNODE_PRICEUPDATER_PROVIDER_URL")
}
if os.Getenv("HEZNODE_PRICEUPDATER_PROVIDER_URLEXTRAPARAMS") != "" {
provider.URLExtraParams = os.Getenv("HEZNODE_PRICEUPDATER_PROVIDER_URLEXTRAPARAMS")
}
if os.Getenv("HEZNODE_PRICEUPDATER_PROVIDER_SYMBOLS") != "" {
provider.Symbols = os.Getenv("HEZNODE_PRICEUPDATER_PROVIDER_SYMBOLS")
}
if os.Getenv("HEZNODE_PRICEUPDATER_PROVIDER_ADDRESSES") != "" {
provider.Addresses = os.Getenv("HEZNODE_PRICEUPDATER_PROVIDER_ADDRESSES")
}
var providers []priceupdater.Provider
providers = append(providers, provider)
cfg.PriceUpdater.Provider = providers
}
validate := validator.New()
validate.RegisterStructValidation(priceupdater.ProviderValidation, priceupdater.Provider{})
if err := validate.Struct(cfg); err != nil {
return nil, tracerr.Wrap(fmt.Errorf("error validating configuration file: %w", err))
}
Expand All @@ -456,7 +416,6 @@ func LoadAPIServer(path string, coordinator bool) (*APIServer, error) {
log.Warn(err.Error())
}
validate := validator.New()
validate.RegisterStructValidation(priceupdater.ProviderValidation, priceupdater.Provider{})
if err := validate.Struct(cfg); err != nil {
return nil, tracerr.Wrap(fmt.Errorf("error validating configuration file: %w", err))
}
Expand Down
30 changes: 0 additions & 30 deletions config/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,6 @@ UpdateRecommendedFeeInterval = "10s"
MaxSQLConnections = 100
SQLConnectionTimeout = "2s"
[PriceUpdater]
Interval = "60s"
Priority = "bitfinexV2,CoinGeckoV3"
Statictokens="" # <tokenId>=<forced_price>,<tokenId>=<forced_price>
[PriceUpdater.Fiat]
APIKey=""
URL="https://api.exchangeratesapi.io/v1/"
BaseCurrency="USD"
Currencies="CNY,EUR,JPY,GBP"
[[PriceUpdater.Provider]]
Provider = "bitfinexV2"
BASEURL = "https://api-pub.bitfinex.com/v2/"
URL = "ticker/t"
URLExtraParams = "USD"
Symbols = "2=UST,3=UDC,5=WBT,7=XAUT:,9=SUSHI:,10=COMP:,12=AAVE:,14=LINK:,24=GNT,27=ignore,28=ignore,29=ignore,30=ignore,31=ignore,32=ignore"
[[PriceUpdater.Provider]]
Provider = "CoinGeckoV3"
BASEURL = "https://api.coingecko.com/api/v3/"
URL = "simple/token_price/ethereum?contract_addresses="
URLExtraParams = "&vs_currencies=usd"
Addresses="6=0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,17=0xde30da39c46104798bb5aa3fe8b9e0e1f348163f,18=0x7d1afa7b718fb893db30a3abc0cfc608aacfebb0,21=0xc944e90c64b2c07662a292be6244bdf05cda44a7,26=0xD533a949740bb3306d119CC777fa900bA034cd52,27=ignore,28=ignore,29=ignore,30=ignore,31=ignore,32=ignore"
[Debug]
APIAddress = "0.0.0.0:12345"
MeddlerLogs = true
GinDebugMode = false
[StateDB]
Path = "/var/hermez/statedb"
Keep = 256
Expand Down
20 changes: 0 additions & 20 deletions db/historydb/historydb.go
Original file line number Diff line number Diff line change
Expand Up @@ -486,26 +486,6 @@ func (hdb *HistoryDB) UpdateTokenValueByTokenID(tokenID uint, value float64) err
return tracerr.Wrap(err)
}

// UpdateFiatPrice updates the USD value per currency
func (hdb *HistoryDB) UpdateFiatPrice(currency string, baseCurrency string, price float64) error {
// last_update field is gonna be updated automatically by the trigger trigger_fiat_price_update
_, err := hdb.dbWrite.Exec(
"UPDATE fiat SET price = $1 WHERE currency = $2 AND base_currency = $3;",
price, currency, baseCurrency,
)
return tracerr.Wrap(err)
}

// CreateFiatPrice creates a new entry for a new currency or pair currency/baseCurrency
func (hdb *HistoryDB) CreateFiatPrice(currency string, baseCurrency string, price float64) error {
// last_update field is gonna be filled automatically by the trigger trigger_fiat_price_update
_, err := hdb.dbWrite.Exec(
"INSERT INTO fiat(currency, base_currency, price) VALUES ($1, $2, $3);",
currency, baseCurrency, price,
)
return tracerr.Wrap(err)
}

// GetFiatPrice recover the price for a currency
func (hdb *HistoryDB) GetFiatPrice(currency, baseCurrency string) (FiatCurrency, error) {
var currencyPrice = &FiatCurrency{}
Expand Down
4 changes: 2 additions & 2 deletions db/migrations/0008_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/stretchr/testify/assert"
)

// This migration creates the fiat table
// This migration updates the tx_pool table

type migrationTest0008 struct{}

Expand Down Expand Up @@ -86,7 +86,7 @@ func (m migrationTest0008) RunAssertsAfterMigrationUp(t *testing.T, db *sqlx.DB)
}

func (m migrationTest0008) RunAssertsAfterMigrationDown(t *testing.T, db *sqlx.DB) {
// check that the fiat table is not created and I can't insert data
// check that the new fields can't be inserted in tx_pool table
const queryInsert = `INSERT INTO tx_pool (tx_id,
from_idx,
effective_from_eth_addr,
Expand Down
33 changes: 0 additions & 33 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ import (
"github.com/hermeznetwork/hermez-node/eth"
"github.com/hermeznetwork/hermez-node/etherscan"
"github.com/hermeznetwork/hermez-node/log"
"github.com/hermeznetwork/hermez-node/priceupdater"
"github.com/hermeznetwork/hermez-node/prover"
"github.com/hermeznetwork/hermez-node/synchronizer"
"github.com/hermeznetwork/hermez-node/test/debugapi"
Expand Down Expand Up @@ -76,7 +75,6 @@ type Node struct {
nodeAPI *NodeAPI
stateAPIUpdater *stateapiupdater.Updater
debugAPI *debugapi.DebugAPI
priceUpdater *priceupdater.PriceUpdater
// Coordinator
coord *coordinator.Coordinator

Expand Down Expand Up @@ -471,22 +469,11 @@ func NewNode(mode Mode, cfg *config.Node, version string) (*Node, error) {
if cfg.Debug.APIAddress != "" {
debugAPI = debugapi.NewDebugAPI(cfg.Debug.APIAddress, stateDB, sync)
}
priceUpdater, err := priceupdater.NewPriceUpdater(
cfg.PriceUpdater.Priority,
cfg.PriceUpdater.Provider,
cfg.PriceUpdater.Statictokens,
cfg.PriceUpdater.Fiat,
historyDB,
)
if err != nil {
return nil, tracerr.Wrap(err)
}
ctx, cancel := context.WithCancel(context.Background())
return &Node{
stateAPIUpdater: stateAPIUpdater,
nodeAPI: nodeAPI,
debugAPI: debugAPI,
priceUpdater: priceUpdater,
coord: coord,
sync: sync,
cfg: cfg,
Expand Down Expand Up @@ -811,26 +798,6 @@ func (n *Node) StartSynchronizer() {
}
}
}()

n.wg.Add(1)
go func() {
for {
select {
case <-n.ctx.Done():
log.Info("PriceUpdater done")
n.wg.Done()
return
case <-time.After(n.cfg.PriceUpdater.Interval.Duration):
if err := n.priceUpdater.UpdateFiatPrices(n.ctx); err != nil {
log.Errorw("PriceUpdater.UpdateFiatPrices()", "err", err)
}
if err := n.priceUpdater.UpdateTokenList(); err != nil {
log.Errorw("PriceUpdater.UpdateTokenList()", "err", err)
}
n.priceUpdater.UpdatePrices(n.ctx)
}
}
}()
}

// StartDebugAPI starts the DebugAPI
Expand Down
Loading

0 comments on commit b01d1b4

Please sign in to comment.