Browse Source

Merge pull request #574 from hermeznetwork/feature/apirecommendedfeeuseminfee

In API recommended fee, use minFeeUSD as min value
feature/edu
arnau 3 years ago
committed by GitHub
parent
commit
11a0707746
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 31 additions and 5 deletions
  1. +1
    -1
      api/api_test.go
  2. +11
    -3
      api/state.go
  3. +5
    -1
      api/state_test.go
  4. +6
    -0
      db/l2db/l2db.go
  5. +8
    -0
      node/node.go

+ 1
- 1
api/api_test.go

@ -594,7 +594,7 @@ func TestTimeout(t *testing.T) {
hdbTO := historydb.NewHistoryDB(databaseTO, apiConnConTO)
require.NoError(t, err)
// L2DB
l2DBTO := l2db.NewL2DB(databaseTO, 10, 1000, 0.0, 24*time.Hour, apiConnConTO)
l2DBTO := l2db.NewL2DB(databaseTO, 10, 1000, 1.0, 24*time.Hour, apiConnConTO)
// API
apiGinTO := gin.Default()

+ 11
- 3
api/state.go

@ -3,6 +3,7 @@ package api
import (
"database/sql"
"fmt"
"math"
"math/big"
"net/http"
"time"
@ -297,10 +298,17 @@ func (a *API) UpdateRecommendedFee() error {
if err != nil {
return tracerr.Wrap(err)
}
var minFeeUSD float64
if a.l2 != nil {
minFeeUSD = a.l2.MinFeeUSD()
}
a.status.Lock()
a.status.RecommendedFee.ExistingAccount = feeExistingAccount
a.status.RecommendedFee.CreatesAccount = createAccountExtraFeePercentage * feeExistingAccount
a.status.RecommendedFee.CreatesAccountAndRegister = createAccountInternalExtraFeePercentage * feeExistingAccount
a.status.RecommendedFee.ExistingAccount =
math.Max(feeExistingAccount, minFeeUSD)
a.status.RecommendedFee.CreatesAccount =
math.Max(createAccountExtraFeePercentage*feeExistingAccount, minFeeUSD)
a.status.RecommendedFee.CreatesAccountAndRegister =
math.Max(createAccountInternalExtraFeePercentage*feeExistingAccount, minFeeUSD)
a.status.Unlock()
return nil
}

+ 5
- 1
api/state_test.go

@ -149,7 +149,11 @@ func TestUpdateMetrics(t *testing.T) {
func TestUpdateRecommendedFee(t *testing.T) {
err := api.UpdateRecommendedFee()
assert.NoError(t, err)
assert.Greater(t, api.status.RecommendedFee.ExistingAccount, float64(0))
var minFeeUSD float64
if api.l2 != nil {
minFeeUSD = api.l2.MinFeeUSD()
}
assert.Greater(t, api.status.RecommendedFee.ExistingAccount, minFeeUSD)
assert.Equal(t, api.status.RecommendedFee.CreatesAccount,
api.status.RecommendedFee.ExistingAccount*createAccountExtraFeePercentage)
assert.Equal(t, api.status.RecommendedFee.CreatesAccountAndRegister,

+ 6
- 0
db/l2db/l2db.go

@ -56,6 +56,12 @@ func (l2db *L2DB) DB() *sqlx.DB {
return l2db.db
}
// MinFeeUSD returns the minimum fee in USD that is required to accept txs into
// the pool
func (l2db *L2DB) MinFeeUSD() float64 {
return l2db.minFeeUSD
}
// AddAccountCreationAuth inserts an account creation authorization into the DB
func (l2db *L2DB) AddAccountCreationAuth(auth *common.AccountCreationAuth) error {
_, err := l2db.db.Exec(

+ 8
- 0
node/node.go

@ -649,6 +649,10 @@ func (n *Node) StartNodeAPI() {
n.wg.Add(1)
go func() {
// Do an initial update on startup
if err := n.nodeAPI.api.UpdateMetrics(); err != nil {
log.Errorw("API.UpdateMetrics", "err", err)
}
for {
select {
case <-n.ctx.Done():
@ -665,6 +669,10 @@ func (n *Node) StartNodeAPI() {
n.wg.Add(1)
go func() {
// Do an initial update on startup
if err := n.nodeAPI.api.UpdateRecommendedFee(); err != nil {
log.Errorw("API.UpdateRecommendedFee", "err", err)
}
for {
select {
case <-n.ctx.Done():

Loading…
Cancel
Save