mirror of
https://github.com/arnaucube/hermez-node.git
synced 2026-02-07 03:16:45 +01:00
In API recommended fee, use minFeeUSD as min value
This commit is contained in:
@@ -594,7 +594,7 @@ func TestTimeout(t *testing.T) {
|
|||||||
hdbTO := historydb.NewHistoryDB(databaseTO, apiConnConTO)
|
hdbTO := historydb.NewHistoryDB(databaseTO, apiConnConTO)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
// L2DB
|
// 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
|
// API
|
||||||
apiGinTO := gin.Default()
|
apiGinTO := gin.Default()
|
||||||
|
|||||||
14
api/state.go
14
api/state.go
@@ -3,6 +3,7 @@ package api
|
|||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"math"
|
||||||
"math/big"
|
"math/big"
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
@@ -297,10 +298,17 @@ func (a *API) UpdateRecommendedFee() error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return tracerr.Wrap(err)
|
return tracerr.Wrap(err)
|
||||||
}
|
}
|
||||||
|
var minFeeUSD float64
|
||||||
|
if a.l2 != nil {
|
||||||
|
minFeeUSD = a.l2.MinFeeUSD()
|
||||||
|
}
|
||||||
a.status.Lock()
|
a.status.Lock()
|
||||||
a.status.RecommendedFee.ExistingAccount = feeExistingAccount
|
a.status.RecommendedFee.ExistingAccount =
|
||||||
a.status.RecommendedFee.CreatesAccount = createAccountExtraFeePercentage * feeExistingAccount
|
math.Max(feeExistingAccount, minFeeUSD)
|
||||||
a.status.RecommendedFee.CreatesAccountAndRegister = createAccountInternalExtraFeePercentage * feeExistingAccount
|
a.status.RecommendedFee.CreatesAccount =
|
||||||
|
math.Max(createAccountExtraFeePercentage*feeExistingAccount, minFeeUSD)
|
||||||
|
a.status.RecommendedFee.CreatesAccountAndRegister =
|
||||||
|
math.Max(createAccountInternalExtraFeePercentage*feeExistingAccount, minFeeUSD)
|
||||||
a.status.Unlock()
|
a.status.Unlock()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -149,7 +149,11 @@ func TestUpdateMetrics(t *testing.T) {
|
|||||||
func TestUpdateRecommendedFee(t *testing.T) {
|
func TestUpdateRecommendedFee(t *testing.T) {
|
||||||
err := api.UpdateRecommendedFee()
|
err := api.UpdateRecommendedFee()
|
||||||
assert.NoError(t, err)
|
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,
|
assert.Equal(t, api.status.RecommendedFee.CreatesAccount,
|
||||||
api.status.RecommendedFee.ExistingAccount*createAccountExtraFeePercentage)
|
api.status.RecommendedFee.ExistingAccount*createAccountExtraFeePercentage)
|
||||||
assert.Equal(t, api.status.RecommendedFee.CreatesAccountAndRegister,
|
assert.Equal(t, api.status.RecommendedFee.CreatesAccountAndRegister,
|
||||||
|
|||||||
@@ -56,6 +56,12 @@ func (l2db *L2DB) DB() *sqlx.DB {
|
|||||||
return l2db.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
|
// AddAccountCreationAuth inserts an account creation authorization into the DB
|
||||||
func (l2db *L2DB) AddAccountCreationAuth(auth *common.AccountCreationAuth) error {
|
func (l2db *L2DB) AddAccountCreationAuth(auth *common.AccountCreationAuth) error {
|
||||||
_, err := l2db.db.Exec(
|
_, err := l2db.db.Exec(
|
||||||
|
|||||||
@@ -649,6 +649,10 @@ func (n *Node) StartNodeAPI() {
|
|||||||
|
|
||||||
n.wg.Add(1)
|
n.wg.Add(1)
|
||||||
go func() {
|
go func() {
|
||||||
|
// Do an initial update on startup
|
||||||
|
if err := n.nodeAPI.api.UpdateMetrics(); err != nil {
|
||||||
|
log.Errorw("API.UpdateMetrics", "err", err)
|
||||||
|
}
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-n.ctx.Done():
|
case <-n.ctx.Done():
|
||||||
@@ -665,6 +669,10 @@ func (n *Node) StartNodeAPI() {
|
|||||||
|
|
||||||
n.wg.Add(1)
|
n.wg.Add(1)
|
||||||
go func() {
|
go func() {
|
||||||
|
// Do an initial update on startup
|
||||||
|
if err := n.nodeAPI.api.UpdateRecommendedFee(); err != nil {
|
||||||
|
log.Errorw("API.UpdateRecommendedFee", "err", err)
|
||||||
|
}
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-n.ctx.Done():
|
case <-n.ctx.Done():
|
||||||
|
|||||||
Reference in New Issue
Block a user