mirror of
https://github.com/arnaucube/hermez-node.git
synced 2026-02-07 11:26:44 +01:00
Merge pull request #651 from hermeznetwork/feature/total-txs-in-pool
API change names and add poolLoad, add maxFeeUSD
This commit is contained in:
@@ -209,7 +209,7 @@ func TestMain(m *testing.M) {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
// L2DB
|
// L2DB
|
||||||
l2DB := l2db.NewL2DB(database, database, 10, 1000, 0.0, 24*time.Hour, apiConnCon)
|
l2DB := l2db.NewL2DB(database, database, 10, 1000, 0.0, 1000.0, 24*time.Hour, apiConnCon)
|
||||||
test.WipeDB(l2DB.DB()) // this will clean HistoryDB and L2DB
|
test.WipeDB(l2DB.DB()) // this will clean HistoryDB and L2DB
|
||||||
// Config (smart contract constants)
|
// Config (smart contract constants)
|
||||||
chainID := uint16(0)
|
chainID := uint16(0)
|
||||||
@@ -240,6 +240,7 @@ func TestMain(m *testing.M) {
|
|||||||
nodeConfig := &historydb.NodeConfig{
|
nodeConfig := &historydb.NodeConfig{
|
||||||
MaxPoolTxs: 10,
|
MaxPoolTxs: 10,
|
||||||
MinFeeUSD: 0,
|
MinFeeUSD: 0,
|
||||||
|
MaxFeeUSD: 10000000000,
|
||||||
}
|
}
|
||||||
if err := hdb.SetNodeConfig(nodeConfig); err != nil {
|
if err := hdb.SetNodeConfig(nodeConfig); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
@@ -615,7 +616,7 @@ func TestTimeout(t *testing.T) {
|
|||||||
hdbTO := historydb.NewHistoryDB(databaseTO, databaseTO, apiConnConTO)
|
hdbTO := historydb.NewHistoryDB(databaseTO, databaseTO, apiConnConTO)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
// L2DB
|
// L2DB
|
||||||
l2DBTO := l2db.NewL2DB(databaseTO, databaseTO, 10, 1000, 1.0, 24*time.Hour, apiConnConTO)
|
l2DBTO := l2db.NewL2DB(databaseTO, databaseTO, 10, 1000, 1.0, 1000.0, 24*time.Hour, apiConnConTO)
|
||||||
|
|
||||||
// API
|
// API
|
||||||
apiGinTO := gin.Default()
|
apiGinTO := gin.Default()
|
||||||
|
|||||||
@@ -145,8 +145,8 @@ func TestUpdateMetrics(t *testing.T) {
|
|||||||
assert.Greater(t, ni.StateAPI.Metrics.TransactionsPerBatch, float64(0))
|
assert.Greater(t, ni.StateAPI.Metrics.TransactionsPerBatch, float64(0))
|
||||||
assert.Greater(t, ni.StateAPI.Metrics.BatchFrequency, float64(0))
|
assert.Greater(t, ni.StateAPI.Metrics.BatchFrequency, float64(0))
|
||||||
assert.Greater(t, ni.StateAPI.Metrics.TransactionsPerSecond, float64(0))
|
assert.Greater(t, ni.StateAPI.Metrics.TransactionsPerSecond, float64(0))
|
||||||
assert.Greater(t, ni.StateAPI.Metrics.TotalAccounts, int64(0))
|
assert.Greater(t, ni.StateAPI.Metrics.TokenAccounts, int64(0))
|
||||||
assert.Greater(t, ni.StateAPI.Metrics.TotalBJJs, int64(0))
|
assert.Greater(t, ni.StateAPI.Metrics.Wallets, int64(0))
|
||||||
assert.Greater(t, ni.StateAPI.Metrics.AvgTransactionFee, float64(0))
|
assert.Greater(t, ni.StateAPI.Metrics.AvgTransactionFee, float64(0))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -210,8 +210,8 @@ func TestGetState(t *testing.T) {
|
|||||||
assert.Greater(t, status.Metrics.TransactionsPerBatch, float64(0))
|
assert.Greater(t, status.Metrics.TransactionsPerBatch, float64(0))
|
||||||
assert.Greater(t, status.Metrics.BatchFrequency, float64(0))
|
assert.Greater(t, status.Metrics.BatchFrequency, float64(0))
|
||||||
assert.Greater(t, status.Metrics.TransactionsPerSecond, float64(0))
|
assert.Greater(t, status.Metrics.TransactionsPerSecond, float64(0))
|
||||||
assert.Greater(t, status.Metrics.TotalAccounts, int64(0))
|
assert.Greater(t, status.Metrics.TokenAccounts, int64(0))
|
||||||
assert.Greater(t, status.Metrics.TotalBJJs, int64(0))
|
assert.Greater(t, status.Metrics.Wallets, int64(0))
|
||||||
assert.Greater(t, status.Metrics.AvgTransactionFee, float64(0))
|
assert.Greater(t, status.Metrics.AvgTransactionFee, float64(0))
|
||||||
// Recommended fee
|
// Recommended fee
|
||||||
// TODO: perform real asserts (not just greater than 0)
|
// TODO: perform real asserts (not just greater than 0)
|
||||||
|
|||||||
@@ -2569,9 +2569,9 @@ components:
|
|||||||
description: List of next coordinators to forge.
|
description: List of next coordinators to forge.
|
||||||
items:
|
items:
|
||||||
$ref: '#/components/schemas/NextForger'
|
$ref: '#/components/schemas/NextForger'
|
||||||
NodeConfig:
|
Node:
|
||||||
type: object
|
type: object
|
||||||
description: Configuration of the coordinator node. Note that this is specific for each coordinator.
|
description: Configuration and metrics of the coordinator node. Note that this is specific for each coordinator.
|
||||||
properties:
|
properties:
|
||||||
forgeDelay:
|
forgeDelay:
|
||||||
type: number
|
type: number
|
||||||
@@ -2581,9 +2581,14 @@ components:
|
|||||||
forge at the maximum rate. Note that this is a configuration parameter of a node,
|
forge at the maximum rate. Note that this is a configuration parameter of a node,
|
||||||
so each coordinator may have a different value.
|
so each coordinator may have a different value.
|
||||||
example: 193.4
|
example: 193.4
|
||||||
|
poolLoad:
|
||||||
|
type: number
|
||||||
|
description: Number of pending transactions in the pool
|
||||||
|
example: 23201
|
||||||
additionalProperties: false
|
additionalProperties: false
|
||||||
required:
|
required:
|
||||||
- forgeDelay
|
- forgeDelay
|
||||||
|
- poolLoad
|
||||||
State:
|
State:
|
||||||
type: object
|
type: object
|
||||||
description: Gobal variables of the network
|
description: Gobal variables of the network
|
||||||
@@ -2600,8 +2605,8 @@ components:
|
|||||||
$ref: '#/components/schemas/StateWithdrawDelayer'
|
$ref: '#/components/schemas/StateWithdrawDelayer'
|
||||||
recommendedFee:
|
recommendedFee:
|
||||||
$ref: '#/components/schemas/RecommendedFee'
|
$ref: '#/components/schemas/RecommendedFee'
|
||||||
nodeConfig:
|
node:
|
||||||
$ref: '#/components/schemas/NodeConfig'
|
$ref: '#/components/schemas/Node'
|
||||||
additionalProperties: false
|
additionalProperties: false
|
||||||
required:
|
required:
|
||||||
- network
|
- network
|
||||||
@@ -2610,7 +2615,7 @@ components:
|
|||||||
- auction
|
- auction
|
||||||
- withdrawalDelayer
|
- withdrawalDelayer
|
||||||
- recommendedFee
|
- recommendedFee
|
||||||
- nodeConfig
|
- node
|
||||||
StateNetwork:
|
StateNetwork:
|
||||||
type: object
|
type: object
|
||||||
description: Gobal statistics of the network
|
description: Gobal statistics of the network
|
||||||
@@ -2813,11 +2818,11 @@ components:
|
|||||||
type: number
|
type: number
|
||||||
description: Average transactions per second in the last 24 hours.
|
description: Average transactions per second in the last 24 hours.
|
||||||
example: 302.3
|
example: 302.3
|
||||||
totalAccounts:
|
tokenAccounts:
|
||||||
type: integer
|
type: integer
|
||||||
description: Number of created accounts.
|
description: Number of created accounts.
|
||||||
example: 90473
|
example: 90473
|
||||||
totalBJJs:
|
wallets:
|
||||||
type: integer
|
type: integer
|
||||||
description: Number of different registered BJJs.
|
description: Number of different registered BJJs.
|
||||||
example: 23067
|
example: 23067
|
||||||
@@ -2834,8 +2839,8 @@ components:
|
|||||||
- transactionsPerBatch
|
- transactionsPerBatch
|
||||||
- batchFrequency
|
- batchFrequency
|
||||||
- transactionsPerSecond
|
- transactionsPerSecond
|
||||||
- totalAccounts
|
- tokenAccounts
|
||||||
- totalBJJs
|
- wallets
|
||||||
- avgTransactionFee
|
- avgTransactionFee
|
||||||
- estimatedTimeToForgeL1
|
- estimatedTimeToForgeL1
|
||||||
PendingItems:
|
PendingItems:
|
||||||
|
|||||||
@@ -99,6 +99,7 @@ BJJ = "0x1b176232f78ba0d388ecc5f4896eca2d3b3d4f272092469f559247297f5c0c13"
|
|||||||
SafetyPeriod = 10
|
SafetyPeriod = 10
|
||||||
MaxTxs = 512
|
MaxTxs = 512
|
||||||
MinFeeUSD = 0.0
|
MinFeeUSD = 0.0
|
||||||
|
MaxFeeUSD = 50.0
|
||||||
TTL = "24h"
|
TTL = "24h"
|
||||||
PurgeBatchDelay = 10
|
PurgeBatchDelay = 10
|
||||||
InvalidateBatchDelay = 20
|
InvalidateBatchDelay = 20
|
||||||
|
|||||||
@@ -318,6 +318,7 @@ func cmdDiscard(c *cli.Context) error {
|
|||||||
cfg.Coordinator.L2DB.SafetyPeriod,
|
cfg.Coordinator.L2DB.SafetyPeriod,
|
||||||
cfg.Coordinator.L2DB.MaxTxs,
|
cfg.Coordinator.L2DB.MaxTxs,
|
||||||
cfg.Coordinator.L2DB.MinFeeUSD,
|
cfg.Coordinator.L2DB.MinFeeUSD,
|
||||||
|
cfg.Coordinator.L2DB.MaxFeeUSD,
|
||||||
cfg.Coordinator.L2DB.TTL.Duration,
|
cfg.Coordinator.L2DB.TTL.Duration,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -144,6 +144,10 @@ type Coordinator struct {
|
|||||||
// order to be accepted into the pool. Txs with lower than
|
// order to be accepted into the pool. Txs with lower than
|
||||||
// minimum fee will be rejected at the API level.
|
// minimum fee will be rejected at the API level.
|
||||||
MinFeeUSD float64
|
MinFeeUSD float64
|
||||||
|
// MaxFeeUSD is the maximum fee in USD that a tx must pay in
|
||||||
|
// order to be accepted into the pool. Txs with greater than
|
||||||
|
// maximum fee will be rejected at the API level.
|
||||||
|
MaxFeeUSD float64 `validate:"required"`
|
||||||
// TTL is the Time To Live for L2Txs in the pool. Once MaxTxs
|
// TTL is the Time To Live for L2Txs in the pool. Once MaxTxs
|
||||||
// L2Txs is reached, L2Txs older than TTL will be deleted.
|
// L2Txs is reached, L2Txs older than TTL will be deleted.
|
||||||
TTL Duration `validate:"required"`
|
TTL Duration `validate:"required"`
|
||||||
@@ -376,6 +380,10 @@ type APIServer struct {
|
|||||||
// order to be accepted into the pool. Txs with lower than
|
// order to be accepted into the pool. Txs with lower than
|
||||||
// minimum fee will be rejected at the API level.
|
// minimum fee will be rejected at the API level.
|
||||||
MinFeeUSD float64
|
MinFeeUSD float64
|
||||||
|
// MaxFeeUSD is the maximum fee in USD that a tx must pay in
|
||||||
|
// order to be accepted into the pool. Txs with greater than
|
||||||
|
// maximum fee will be rejected at the API level.
|
||||||
|
MaxFeeUSD float64 `validate:"required"`
|
||||||
} `validate:"required"`
|
} `validate:"required"`
|
||||||
}
|
}
|
||||||
Debug NodeDebug `validate:"required"`
|
Debug NodeDebug `validate:"required"`
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ func newTestModules(t *testing.T) modules {
|
|||||||
db, err := dbUtils.InitSQLDB(5432, "localhost", "hermez", pass, "hermez")
|
db, err := dbUtils.InitSQLDB(5432, "localhost", "hermez", pass, "hermez")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
test.WipeDB(db)
|
test.WipeDB(db)
|
||||||
l2DB := l2db.NewL2DB(db, db, 10, 100, 0.0, 24*time.Hour, nil)
|
l2DB := l2db.NewL2DB(db, db, 10, 100, 0.0, 1000.0, 24*time.Hour, nil)
|
||||||
historyDB := historydb.NewHistoryDB(db, db, nil)
|
historyDB := historydb.NewHistoryDB(db, db, nil)
|
||||||
|
|
||||||
txSelDBPath, err = ioutil.TempDir("", "tmpTxSelDB")
|
txSelDBPath, err = ioutil.TempDir("", "tmpTxSelDB")
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ func newL2DB(t *testing.T) *l2db.L2DB {
|
|||||||
db, err := dbUtils.InitSQLDB(5432, "localhost", "hermez", pass, "hermez")
|
db, err := dbUtils.InitSQLDB(5432, "localhost", "hermez", pass, "hermez")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
test.WipeDB(db)
|
test.WipeDB(db)
|
||||||
return l2db.NewL2DB(db, db, 10, 100, 0.0, 24*time.Hour, nil)
|
return l2db.NewL2DB(db, db, 10, 100, 0.0, 1000.0, 24*time.Hour, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func newStateDB(t *testing.T) *statedb.LocalStateDB {
|
func newStateDB(t *testing.T) *statedb.LocalStateDB {
|
||||||
|
|||||||
@@ -1083,12 +1083,8 @@ func (hdb *HistoryDB) GetNextForgersInternalAPI(auctionVars *common.AuctionVaria
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetMetricsInternalAPI returns the MetricsAPI
|
// GetMetricsInternalAPI returns the MetricsAPI
|
||||||
func (hdb *HistoryDB) GetMetricsInternalAPI(lastBatchNum common.BatchNum) (*MetricsAPI, error) {
|
func (hdb *HistoryDB) GetMetricsInternalAPI(lastBatchNum common.BatchNum) (metrics *MetricsAPI, poolLoad int64, err error) {
|
||||||
var metrics MetricsAPI
|
metrics = &MetricsAPI{}
|
||||||
// Get the first and last batch of the last 24h and their timestamps
|
|
||||||
// if u.state.Network.LastBatch == nil {
|
|
||||||
// return &metrics, nil
|
|
||||||
// }
|
|
||||||
type period struct {
|
type period struct {
|
||||||
FromBatchNum common.BatchNum `meddler:"from_batch_num"`
|
FromBatchNum common.BatchNum `meddler:"from_batch_num"`
|
||||||
FromTimestamp time.Time `meddler:"from_timestamp"`
|
FromTimestamp time.Time `meddler:"from_timestamp"`
|
||||||
@@ -1106,7 +1102,7 @@ func (hdb *HistoryDB) GetMetricsInternalAPI(lastBatchNum common.BatchNum) (*Metr
|
|||||||
FROM batch INNER JOIN block ON batch.eth_block_num = block.eth_block_num
|
FROM batch INNER JOIN block ON batch.eth_block_num = block.eth_block_num
|
||||||
WHERE block.timestamp >= NOW() - INTERVAL '24 HOURS';`,
|
WHERE block.timestamp >= NOW() - INTERVAL '24 HOURS';`,
|
||||||
); err != nil {
|
); err != nil {
|
||||||
return nil, tracerr.Wrap(err)
|
return nil, 0, tracerr.Wrap(err)
|
||||||
}
|
}
|
||||||
// Get the amount of txs of that period
|
// Get the amount of txs of that period
|
||||||
row := hdb.dbRead.QueryRow(
|
row := hdb.dbRead.QueryRow(
|
||||||
@@ -1115,7 +1111,7 @@ func (hdb *HistoryDB) GetMetricsInternalAPI(lastBatchNum common.BatchNum) (*Metr
|
|||||||
)
|
)
|
||||||
var nTxs int
|
var nTxs int
|
||||||
if err := row.Scan(&nTxs); err != nil {
|
if err := row.Scan(&nTxs); err != nil {
|
||||||
return nil, tracerr.Wrap(err)
|
return nil, 0, tracerr.Wrap(err)
|
||||||
}
|
}
|
||||||
// Set txs/s
|
// Set txs/s
|
||||||
seconds := p.ToTimestamp.Sub(p.FromTimestamp).Seconds()
|
seconds := p.ToTimestamp.Sub(p.FromTimestamp).Seconds()
|
||||||
@@ -1141,7 +1137,7 @@ func (hdb *HistoryDB) GetMetricsInternalAPI(lastBatchNum common.BatchNum) (*Metr
|
|||||||
)
|
)
|
||||||
var totalFee float64
|
var totalFee float64
|
||||||
if err := row.Scan(&totalFee); err != nil {
|
if err := row.Scan(&totalFee); err != nil {
|
||||||
return nil, tracerr.Wrap(err)
|
return nil, 0, tracerr.Wrap(err)
|
||||||
}
|
}
|
||||||
// Set batch frequency
|
// Set batch frequency
|
||||||
metrics.BatchFrequency = seconds / float64(nBatches)
|
metrics.BatchFrequency = seconds / float64(nBatches)
|
||||||
@@ -1152,7 +1148,7 @@ func (hdb *HistoryDB) GetMetricsInternalAPI(lastBatchNum common.BatchNum) (*Metr
|
|||||||
)
|
)
|
||||||
var nL2Txs int
|
var nL2Txs int
|
||||||
if err := row.Scan(&nL2Txs); err != nil {
|
if err := row.Scan(&nL2Txs); err != nil {
|
||||||
return nil, tracerr.Wrap(err)
|
return nil, 0, tracerr.Wrap(err)
|
||||||
}
|
}
|
||||||
if nL2Txs > 0 {
|
if nL2Txs > 0 {
|
||||||
metrics.AvgTransactionFee = totalFee / float64(nL2Txs)
|
metrics.AvgTransactionFee = totalFee / float64(nL2Txs)
|
||||||
@@ -1161,18 +1157,18 @@ func (hdb *HistoryDB) GetMetricsInternalAPI(lastBatchNum common.BatchNum) (*Metr
|
|||||||
}
|
}
|
||||||
// Get and set amount of registered accounts
|
// Get and set amount of registered accounts
|
||||||
type registeredAccounts struct {
|
type registeredAccounts struct {
|
||||||
TotalIdx int64 `meddler:"total_idx"`
|
TokenAccounts int64 `meddler:"token_accounts"`
|
||||||
TotalBJJ int64 `meddler:"total_bjj"`
|
Wallets int64 `meddler:"wallets"`
|
||||||
}
|
}
|
||||||
ra := ®isteredAccounts{}
|
ra := ®isteredAccounts{}
|
||||||
if err := meddler.QueryRow(
|
if err := meddler.QueryRow(
|
||||||
hdb.dbRead, ra,
|
hdb.dbRead, ra,
|
||||||
`SELECT COUNT(*) AS total_bjj, COUNT(DISTINCT(bjj)) AS total_idx FROM account;`,
|
`SELECT COUNT(*) AS token_accounts, COUNT(DISTINCT(bjj)) AS wallets FROM account;`,
|
||||||
); err != nil {
|
); err != nil {
|
||||||
return nil, tracerr.Wrap(err)
|
return nil, 0, tracerr.Wrap(err)
|
||||||
}
|
}
|
||||||
metrics.TotalAccounts = ra.TotalIdx
|
metrics.TokenAccounts = ra.TokenAccounts
|
||||||
metrics.TotalBJJs = ra.TotalBJJ
|
metrics.Wallets = ra.Wallets
|
||||||
// Get and set estimated time to forge L1 tx
|
// Get and set estimated time to forge L1 tx
|
||||||
row = hdb.dbRead.QueryRow(
|
row = hdb.dbRead.QueryRow(
|
||||||
`SELECT COALESCE (AVG(EXTRACT(EPOCH FROM (forged.timestamp - added.timestamp))), 0) FROM tx
|
`SELECT COALESCE (AVG(EXTRACT(EPOCH FROM (forged.timestamp - added.timestamp))), 0) FROM tx
|
||||||
@@ -1184,10 +1180,18 @@ func (hdb *HistoryDB) GetMetricsInternalAPI(lastBatchNum common.BatchNum) (*Metr
|
|||||||
)
|
)
|
||||||
var timeToForgeL1 float64
|
var timeToForgeL1 float64
|
||||||
if err := row.Scan(&timeToForgeL1); err != nil {
|
if err := row.Scan(&timeToForgeL1); err != nil {
|
||||||
return nil, tracerr.Wrap(err)
|
return nil, 0, tracerr.Wrap(err)
|
||||||
}
|
}
|
||||||
metrics.EstimatedTimeToForgeL1 = timeToForgeL1
|
metrics.EstimatedTimeToForgeL1 = timeToForgeL1
|
||||||
return &metrics, nil
|
// Get amount of txs in the pool
|
||||||
|
row = hdb.dbRead.QueryRow(
|
||||||
|
`SELECT COUNT(*) FROM tx_pool WHERE state = $1 AND NOT external_delete;`,
|
||||||
|
common.PoolL2TxStatePending,
|
||||||
|
)
|
||||||
|
if err := row.Scan(&poolLoad); err != nil {
|
||||||
|
return nil, 0, tracerr.Wrap(err)
|
||||||
|
}
|
||||||
|
return metrics, poolLoad, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetStateAPI returns the StateAPI
|
// GetStateAPI returns the StateAPI
|
||||||
|
|||||||
@@ -1181,7 +1181,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// GetRecommendedFee returns the RecommendedFee information
|
// GetRecommendedFee returns the RecommendedFee information
|
||||||
func (hdb *HistoryDB) GetRecommendedFee(minFeeUSD float64) (*common.RecommendedFee, error) {
|
func (hdb *HistoryDB) GetRecommendedFee(minFeeUSD, maxFeeUSD float64) (*common.RecommendedFee, error) {
|
||||||
var recommendedFee common.RecommendedFee
|
var recommendedFee common.RecommendedFee
|
||||||
// Get total txs and the batch of the first selected tx of the last hour
|
// Get total txs and the batch of the first selected tx of the last hour
|
||||||
type totalTxsSinceBatchNum struct {
|
type totalTxsSinceBatchNum struct {
|
||||||
@@ -1217,11 +1217,11 @@ func (hdb *HistoryDB) GetRecommendedFee(minFeeUSD float64) (*common.RecommendedF
|
|||||||
} else {
|
} else {
|
||||||
avgTransactionFee = 0
|
avgTransactionFee = 0
|
||||||
}
|
}
|
||||||
recommendedFee.ExistingAccount =
|
recommendedFee.ExistingAccount = math.Min(maxFeeUSD,
|
||||||
math.Max(avgTransactionFee, minFeeUSD)
|
math.Max(avgTransactionFee, minFeeUSD))
|
||||||
recommendedFee.CreatesAccount =
|
recommendedFee.CreatesAccount = math.Min(maxFeeUSD,
|
||||||
math.Max(CreateAccountExtraFeePercentage*avgTransactionFee, minFeeUSD)
|
math.Max(CreateAccountExtraFeePercentage*avgTransactionFee, minFeeUSD))
|
||||||
recommendedFee.CreatesAccountInternal =
|
recommendedFee.CreatesAccountInternal = math.Min(maxFeeUSD,
|
||||||
math.Max(CreateAccountInternalExtraFeePercentage*avgTransactionFee, minFeeUSD)
|
math.Max(CreateAccountInternalExtraFeePercentage*avgTransactionFee, minFeeUSD))
|
||||||
return &recommendedFee, nil
|
return &recommendedFee, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1177,7 +1177,7 @@ func TestGetMetricsAPI(t *testing.T) {
|
|||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
res, err := historyDB.GetMetricsInternalAPI(common.BatchNum(numBatches))
|
res, _, err := historyDB.GetMetricsInternalAPI(common.BatchNum(numBatches))
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
assert.Equal(t, float64(numTx)/float64(numBatches), res.TransactionsPerBatch)
|
assert.Equal(t, float64(numTx)/float64(numBatches), res.TransactionsPerBatch)
|
||||||
@@ -1186,8 +1186,8 @@ func TestGetMetricsAPI(t *testing.T) {
|
|||||||
// There is a -2 as time for first and last batch is not taken into account
|
// There is a -2 as time for first and last batch is not taken into account
|
||||||
assert.InEpsilon(t, float64(frequency)*float64(numBatches-2)/float64(numBatches), res.BatchFrequency, 0.01)
|
assert.InEpsilon(t, float64(frequency)*float64(numBatches-2)/float64(numBatches), res.BatchFrequency, 0.01)
|
||||||
assert.InEpsilon(t, float64(numTx)/float64(frequency*blockNum-frequency), res.TransactionsPerSecond, 0.01)
|
assert.InEpsilon(t, float64(numTx)/float64(frequency*blockNum-frequency), res.TransactionsPerSecond, 0.01)
|
||||||
assert.Equal(t, int64(3), res.TotalAccounts)
|
assert.Equal(t, int64(3), res.TokenAccounts)
|
||||||
assert.Equal(t, int64(3), res.TotalBJJs)
|
assert.Equal(t, int64(3), res.Wallets)
|
||||||
// Til does not set fees
|
// Til does not set fees
|
||||||
assert.Equal(t, float64(0), res.AvgTransactionFee)
|
assert.Equal(t, float64(0), res.AvgTransactionFee)
|
||||||
}
|
}
|
||||||
@@ -1255,22 +1255,22 @@ func TestGetMetricsAPIMoreThan24Hours(t *testing.T) {
|
|||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
res, err := historyDBWithACC.GetMetricsInternalAPI(common.BatchNum(numBatches))
|
res, _, err := historyDBWithACC.GetMetricsInternalAPI(common.BatchNum(numBatches))
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
assert.InEpsilon(t, 1.0, res.TransactionsPerBatch, 0.1)
|
assert.InEpsilon(t, 1.0, res.TransactionsPerBatch, 0.1)
|
||||||
|
|
||||||
assert.InEpsilon(t, res.BatchFrequency, float64(blockTime/time.Second), 0.1)
|
assert.InEpsilon(t, res.BatchFrequency, float64(blockTime/time.Second), 0.1)
|
||||||
assert.InEpsilon(t, 1.0/float64(blockTime/time.Second), res.TransactionsPerSecond, 0.1)
|
assert.InEpsilon(t, 1.0/float64(blockTime/time.Second), res.TransactionsPerSecond, 0.1)
|
||||||
assert.Equal(t, int64(3), res.TotalAccounts)
|
assert.Equal(t, int64(3), res.TokenAccounts)
|
||||||
assert.Equal(t, int64(3), res.TotalBJJs)
|
assert.Equal(t, int64(3), res.Wallets)
|
||||||
// Til does not set fees
|
// Til does not set fees
|
||||||
assert.Equal(t, float64(0), res.AvgTransactionFee)
|
assert.Equal(t, float64(0), res.AvgTransactionFee)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetMetricsAPIEmpty(t *testing.T) {
|
func TestGetMetricsAPIEmpty(t *testing.T) {
|
||||||
test.WipeDB(historyDB.DB())
|
test.WipeDB(historyDB.DB())
|
||||||
_, err := historyDBWithACC.GetMetricsInternalAPI(0)
|
_, _, err := historyDBWithACC.GetMetricsInternalAPI(0)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1485,7 +1485,7 @@ func TestNodeInfo(t *testing.T) {
|
|||||||
addr := ethCommon.HexToAddress("0x1234")
|
addr := ethCommon.HexToAddress("0x1234")
|
||||||
hash := ethCommon.HexToHash("0x5678")
|
hash := ethCommon.HexToHash("0x5678")
|
||||||
stateAPI := &StateAPI{
|
stateAPI := &StateAPI{
|
||||||
NodePublicConfig: NodePublicConfig{
|
NodePublicInfo: NodePublicInfo{
|
||||||
ForgeDelay: 3.1,
|
ForgeDelay: 3.1,
|
||||||
},
|
},
|
||||||
Network: NetworkAPI{
|
Network: NetworkAPI{
|
||||||
@@ -1544,7 +1544,7 @@ func TestNodeInfo(t *testing.T) {
|
|||||||
},
|
},
|
||||||
Metrics: MetricsAPI{
|
Metrics: MetricsAPI{
|
||||||
TransactionsPerBatch: 1.1,
|
TransactionsPerBatch: 1.1,
|
||||||
TotalAccounts: 42,
|
TokenAccounts: 42,
|
||||||
},
|
},
|
||||||
Rollup: *NewRollupVariablesAPI(clientSetup.RollupVariables),
|
Rollup: *NewRollupVariablesAPI(clientSetup.RollupVariables),
|
||||||
Auction: *NewAuctionVariablesAPI(clientSetup.AuctionVariables),
|
Auction: *NewAuctionVariablesAPI(clientSetup.AuctionVariables),
|
||||||
|
|||||||
@@ -35,16 +35,17 @@ type NetworkAPI struct {
|
|||||||
PendingL1Txs int `json:"pendingL1Transactions"`
|
PendingL1Txs int `json:"pendingL1Transactions"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// NodePublicConfig is the configuration of the node that is exposed via API
|
// NodePublicInfo is the configuration and metrics of the node that is exposed via API
|
||||||
type NodePublicConfig struct {
|
type NodePublicInfo struct {
|
||||||
// ForgeDelay in seconds
|
// ForgeDelay in seconds
|
||||||
ForgeDelay float64 `json:"forgeDelay"`
|
ForgeDelay float64 `json:"forgeDelay"`
|
||||||
|
// PoolLoad amount of transactions in the pool
|
||||||
|
PoolLoad int64 `json:"poolLoad"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// StateAPI is an object representing the node and network state exposed via the API
|
// StateAPI is an object representing the node and network state exposed via the API
|
||||||
type StateAPI struct {
|
type StateAPI struct {
|
||||||
// NodePublicConfig is the configuration of the node that is exposed via API
|
NodePublicInfo NodePublicInfo `json:"node"`
|
||||||
NodePublicConfig NodePublicConfig `json:"nodeConfig"`
|
|
||||||
Network NetworkAPI `json:"network"`
|
Network NetworkAPI `json:"network"`
|
||||||
Metrics MetricsAPI `json:"metrics"`
|
Metrics MetricsAPI `json:"metrics"`
|
||||||
Rollup RollupVariablesAPI `json:"rollup"`
|
Rollup RollupVariablesAPI `json:"rollup"`
|
||||||
@@ -64,6 +65,7 @@ type Constants struct {
|
|||||||
type NodeConfig struct {
|
type NodeConfig struct {
|
||||||
MaxPoolTxs uint32
|
MaxPoolTxs uint32
|
||||||
MinFeeUSD float64
|
MinFeeUSD float64
|
||||||
|
MaxFeeUSD float64
|
||||||
ForgeDelay float64
|
ForgeDelay float64
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -314,8 +314,8 @@ type MetricsAPI struct {
|
|||||||
TransactionsPerBatch float64 `json:"transactionsPerBatch"`
|
TransactionsPerBatch float64 `json:"transactionsPerBatch"`
|
||||||
BatchFrequency float64 `json:"batchFrequency"`
|
BatchFrequency float64 `json:"batchFrequency"`
|
||||||
TransactionsPerSecond float64 `json:"transactionsPerSecond"`
|
TransactionsPerSecond float64 `json:"transactionsPerSecond"`
|
||||||
TotalAccounts int64 `json:"totalAccounts" meddler:"total_accounts"`
|
TokenAccounts int64 `json:"tokenAccounts"`
|
||||||
TotalBJJs int64 `json:"totalBJJs" meddler:"total_bjjs"`
|
Wallets int64 `json:"wallets"`
|
||||||
AvgTransactionFee float64 `json:"avgTransactionFee"`
|
AvgTransactionFee float64 `json:"avgTransactionFee"`
|
||||||
EstimatedTimeToForgeL1 float64 `json:"estimatedTimeToForgeL1" meddler:"estimated_time_to_forge_l1"`
|
EstimatedTimeToForgeL1 float64 `json:"estimatedTimeToForgeL1" meddler:"estimated_time_to_forge_l1"`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,6 +62,10 @@ func (l2db *L2DB) AddTxAPI(tx *PoolL2TxWrite) error {
|
|||||||
return tracerr.Wrap(fmt.Errorf("tx.feeUSD (%v) < minFeeUSD (%v)",
|
return tracerr.Wrap(fmt.Errorf("tx.feeUSD (%v) < minFeeUSD (%v)",
|
||||||
feeUSD, l2db.minFeeUSD))
|
feeUSD, l2db.minFeeUSD))
|
||||||
}
|
}
|
||||||
|
if feeUSD > l2db.maxFeeUSD {
|
||||||
|
return tracerr.Wrap(fmt.Errorf("tx.feeUSD (%v) > maxFeeUSD (%v)",
|
||||||
|
feeUSD, l2db.maxFeeUSD))
|
||||||
|
}
|
||||||
|
|
||||||
// Prepare insert SQL query argument parameters
|
// Prepare insert SQL query argument parameters
|
||||||
namesPart, err := meddler.Default.ColumnsQuoted(tx, false)
|
namesPart, err := meddler.Default.ColumnsQuoted(tx, false)
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ type L2DB struct {
|
|||||||
ttl time.Duration
|
ttl time.Duration
|
||||||
maxTxs uint32 // limit of txs that are accepted in the pool
|
maxTxs uint32 // limit of txs that are accepted in the pool
|
||||||
minFeeUSD float64
|
minFeeUSD float64
|
||||||
|
maxFeeUSD float64
|
||||||
apiConnCon *db.APIConnectionController
|
apiConnCon *db.APIConnectionController
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -38,6 +39,7 @@ func NewL2DB(
|
|||||||
safetyPeriod common.BatchNum,
|
safetyPeriod common.BatchNum,
|
||||||
maxTxs uint32,
|
maxTxs uint32,
|
||||||
minFeeUSD float64,
|
minFeeUSD float64,
|
||||||
|
maxFeeUSD float64,
|
||||||
TTL time.Duration,
|
TTL time.Duration,
|
||||||
apiConnCon *db.APIConnectionController,
|
apiConnCon *db.APIConnectionController,
|
||||||
) *L2DB {
|
) *L2DB {
|
||||||
@@ -48,6 +50,7 @@ func NewL2DB(
|
|||||||
ttl: TTL,
|
ttl: TTL,
|
||||||
maxTxs: maxTxs,
|
maxTxs: maxTxs,
|
||||||
minFeeUSD: minFeeUSD,
|
minFeeUSD: minFeeUSD,
|
||||||
|
maxFeeUSD: maxFeeUSD,
|
||||||
apiConnCon: apiConnCon,
|
apiConnCon: apiConnCon,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,9 +37,9 @@ func TestMain(m *testing.M) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
l2DB = NewL2DB(db, db, 10, 1000, 0.0, 24*time.Hour, nil)
|
l2DB = NewL2DB(db, db, 10, 1000, 0.0, 1000.0, 24*time.Hour, nil)
|
||||||
apiConnCon := dbUtils.NewAPIConnectionController(1, time.Second)
|
apiConnCon := dbUtils.NewAPIConnectionController(1, time.Second)
|
||||||
l2DBWithACC = NewL2DB(db, db, 10, 1000, 0.0, 24*time.Hour, apiConnCon)
|
l2DBWithACC = NewL2DB(db, db, 10, 1000, 0.0, 1000.0, 24*time.Hour, apiConnCon)
|
||||||
test.WipeDB(l2DB.DB())
|
test.WipeDB(l2DB.DB())
|
||||||
historyDB = historydb.NewHistoryDB(db, db, nil)
|
historyDB = historydb.NewHistoryDB(db, db, nil)
|
||||||
// Run tests
|
// Run tests
|
||||||
|
|||||||
@@ -230,6 +230,7 @@ func NewNode(mode Mode, cfg *config.Node) (*Node, error) {
|
|||||||
cfg.Coordinator.L2DB.SafetyPeriod,
|
cfg.Coordinator.L2DB.SafetyPeriod,
|
||||||
cfg.Coordinator.L2DB.MaxTxs,
|
cfg.Coordinator.L2DB.MaxTxs,
|
||||||
cfg.Coordinator.L2DB.MinFeeUSD,
|
cfg.Coordinator.L2DB.MinFeeUSD,
|
||||||
|
cfg.Coordinator.L2DB.MaxFeeUSD,
|
||||||
cfg.Coordinator.L2DB.TTL.Duration,
|
cfg.Coordinator.L2DB.TTL.Duration,
|
||||||
apiConnCon,
|
apiConnCon,
|
||||||
)
|
)
|
||||||
@@ -253,6 +254,7 @@ func NewNode(mode Mode, cfg *config.Node) (*Node, error) {
|
|||||||
hdbNodeCfg := historydb.NodeConfig{
|
hdbNodeCfg := historydb.NodeConfig{
|
||||||
MaxPoolTxs: cfg.Coordinator.L2DB.MaxTxs,
|
MaxPoolTxs: cfg.Coordinator.L2DB.MaxTxs,
|
||||||
MinFeeUSD: cfg.Coordinator.L2DB.MinFeeUSD,
|
MinFeeUSD: cfg.Coordinator.L2DB.MinFeeUSD,
|
||||||
|
MaxFeeUSD: cfg.Coordinator.L2DB.MaxFeeUSD,
|
||||||
ForgeDelay: cfg.Coordinator.ForgeDelay.Duration.Seconds(),
|
ForgeDelay: cfg.Coordinator.ForgeDelay.Duration.Seconds(),
|
||||||
}
|
}
|
||||||
if err := historyDB.SetNodeConfig(&hdbNodeCfg); err != nil {
|
if err := historyDB.SetNodeConfig(&hdbNodeCfg); err != nil {
|
||||||
@@ -522,6 +524,7 @@ func NewAPIServer(mode Mode, cfg *config.APIServer) (*APIServer, error) {
|
|||||||
0,
|
0,
|
||||||
cfg.Coordinator.L2DB.MaxTxs,
|
cfg.Coordinator.L2DB.MaxTxs,
|
||||||
cfg.Coordinator.L2DB.MinFeeUSD,
|
cfg.Coordinator.L2DB.MinFeeUSD,
|
||||||
|
cfg.Coordinator.L2DB.MaxFeeUSD,
|
||||||
0,
|
0,
|
||||||
apiConnCon,
|
apiConnCon,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ func NewUpdater(hdb *historydb.HistoryDB, config *historydb.NodeConfig, vars *co
|
|||||||
config: *config,
|
config: *config,
|
||||||
consts: *consts,
|
consts: *consts,
|
||||||
state: historydb.StateAPI{
|
state: historydb.StateAPI{
|
||||||
NodePublicConfig: historydb.NodePublicConfig{
|
NodePublicInfo: historydb.NodePublicInfo{
|
||||||
ForgeDelay: config.ForgeDelay,
|
ForgeDelay: config.ForgeDelay,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -65,7 +65,7 @@ func (u *Updater) SetSCVars(vars *common.SCVariablesPtr) {
|
|||||||
|
|
||||||
// UpdateRecommendedFee update Status.RecommendedFee information
|
// UpdateRecommendedFee update Status.RecommendedFee information
|
||||||
func (u *Updater) UpdateRecommendedFee() error {
|
func (u *Updater) UpdateRecommendedFee() error {
|
||||||
recommendedFee, err := u.hdb.GetRecommendedFee(u.config.MinFeeUSD)
|
recommendedFee, err := u.hdb.GetRecommendedFee(u.config.MinFeeUSD, u.config.MaxFeeUSD)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return tracerr.Wrap(err)
|
return tracerr.Wrap(err)
|
||||||
}
|
}
|
||||||
@@ -84,12 +84,13 @@ func (u *Updater) UpdateMetrics() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
lastBatchNum := lastBatch.BatchNum
|
lastBatchNum := lastBatch.BatchNum
|
||||||
metrics, err := u.hdb.GetMetricsInternalAPI(lastBatchNum)
|
metrics, poolLoad, err := u.hdb.GetMetricsInternalAPI(lastBatchNum)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return tracerr.Wrap(err)
|
return tracerr.Wrap(err)
|
||||||
}
|
}
|
||||||
u.rw.Lock()
|
u.rw.Lock()
|
||||||
u.state.Metrics = *metrics
|
u.state.Metrics = *metrics
|
||||||
|
u.state.NodePublicInfo.PoolLoad = poolLoad
|
||||||
u.rw.Unlock()
|
u.rw.Unlock()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -323,7 +323,7 @@ func newTestModules(t *testing.T) (*statedb.StateDB, *historydb.HistoryDB, *l2db
|
|||||||
test.WipeDB(historyDB.DB())
|
test.WipeDB(historyDB.DB())
|
||||||
|
|
||||||
// Init L2 DB
|
// Init L2 DB
|
||||||
l2DB := l2db.NewL2DB(db, db, 10, 100, 0.0, 24*time.Hour, nil)
|
l2DB := l2db.NewL2DB(db, db, 10, 100, 0.0, 1000.0, 24*time.Hour, nil)
|
||||||
|
|
||||||
return stateDB, historyDB, l2DB
|
return stateDB, historyDB, l2DB
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ func initTxSelector(t *testing.T, chainID uint16, hermezContractAddr ethCommon.A
|
|||||||
pass := os.Getenv("POSTGRES_PASS")
|
pass := os.Getenv("POSTGRES_PASS")
|
||||||
db, err := dbUtils.InitSQLDB(5432, "localhost", "hermez", pass, "hermez")
|
db, err := dbUtils.InitSQLDB(5432, "localhost", "hermez", pass, "hermez")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
l2DB := l2db.NewL2DB(db, db, 10, 100, 0.0, 24*time.Hour, nil)
|
l2DB := l2db.NewL2DB(db, db, 10, 100, 0.0, 1000.0, 24*time.Hour, nil)
|
||||||
|
|
||||||
dir, err := ioutil.TempDir("", "tmpSyncDB")
|
dir, err := ioutil.TempDir("", "tmpSyncDB")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ func initTest(t *testing.T, chainID uint16, hermezContractAddr ethCommon.Address
|
|||||||
pass := os.Getenv("POSTGRES_PASS")
|
pass := os.Getenv("POSTGRES_PASS")
|
||||||
db, err := dbUtils.InitSQLDB(5432, "localhost", "hermez", pass, "hermez")
|
db, err := dbUtils.InitSQLDB(5432, "localhost", "hermez", pass, "hermez")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
l2DB := l2db.NewL2DB(db, db, 10, 100, 0.0, 24*time.Hour, nil)
|
l2DB := l2db.NewL2DB(db, db, 10, 100, 0.0, 1000.0, 24*time.Hour, nil)
|
||||||
|
|
||||||
dir, err := ioutil.TempDir("", "tmpdb")
|
dir, err := ioutil.TempDir("", "tmpdb")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|||||||
Reference in New Issue
Block a user