mirror of
https://github.com/arnaucube/hermez-node.git
synced 2026-02-07 11:26:44 +01:00
Compare commits
3 Commits
hardcoded-
...
fix/packr-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
628c582ea7 | ||
|
|
6c1c157bc3 | ||
|
|
f9ddf88c93 |
13
.github/workflows/release.yml
vendored
13
.github/workflows/release.yml
vendored
@@ -9,18 +9,19 @@ jobs:
|
|||||||
goreleaser:
|
goreleaser:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
-
|
- name: Checkout
|
||||||
name: Checkout
|
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
-
|
- name: Set up Go
|
||||||
name: Set up Go
|
|
||||||
uses: actions/setup-go@v2
|
uses: actions/setup-go@v2
|
||||||
with:
|
with:
|
||||||
go-version: 1.16
|
go-version: 1.16
|
||||||
-
|
- name: Get packr
|
||||||
name: Run GoReleaser
|
run: go get -u github.com/gobuffalo/packr
|
||||||
|
- name: Prepare
|
||||||
|
run: git reset --hard
|
||||||
|
- name: Run GoReleaser
|
||||||
uses: goreleaser/goreleaser-action@v2
|
uses: goreleaser/goreleaser-action@v2
|
||||||
with:
|
with:
|
||||||
version: latest
|
version: latest
|
||||||
|
|||||||
@@ -9,18 +9,8 @@ builds:
|
|||||||
goos:
|
goos:
|
||||||
- linux
|
- linux
|
||||||
- darwin
|
- darwin
|
||||||
- windows
|
goarch:
|
||||||
hooks:
|
- amd64
|
||||||
pre: make migration-pack
|
|
||||||
post: make migration-clean
|
|
||||||
|
|
||||||
archives:
|
|
||||||
- replacements:
|
|
||||||
darwin: Darwin
|
|
||||||
linux: Linux
|
|
||||||
windows: Windows
|
|
||||||
386: i386
|
|
||||||
amd64: x86_64
|
|
||||||
|
|
||||||
checksum:
|
checksum:
|
||||||
name_template: 'checksums.txt'
|
name_template: 'checksums.txt'
|
||||||
|
|||||||
@@ -522,11 +522,16 @@ func TestMain(m *testing.M) {
|
|||||||
WithdrawalDelay: uint64(3000),
|
WithdrawalDelay: uint64(3000),
|
||||||
}
|
}
|
||||||
|
|
||||||
stateAPIUpdater = stateapiupdater.NewUpdater(hdb, nodeConfig, &common.SCVariables{
|
stateAPIUpdater, err = stateapiupdater.NewUpdater(hdb, nodeConfig, &common.SCVariables{
|
||||||
Rollup: rollupVars,
|
Rollup: rollupVars,
|
||||||
Auction: auctionVars,
|
Auction: auctionVars,
|
||||||
WDelayer: wdelayerVars,
|
WDelayer: wdelayerVars,
|
||||||
}, constants)
|
}, constants, &stateapiupdater.RecommendedFeePolicy{
|
||||||
|
PolicyType: stateapiupdater.RecommendedFeePolicyTypeAvgLastHour,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
// Generate test data, as expected to be received/sended from/to the API
|
// Generate test data, as expected to be received/sended from/to the API
|
||||||
testCoords := genTestCoordinators(commonCoords)
|
testCoords := genTestCoordinators(commonCoords)
|
||||||
|
|||||||
@@ -2,10 +2,12 @@ package stateapiupdater
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
|
"fmt"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/hermeznetwork/hermez-node/common"
|
"github.com/hermeznetwork/hermez-node/common"
|
||||||
"github.com/hermeznetwork/hermez-node/db/historydb"
|
"github.com/hermeznetwork/hermez-node/db/historydb"
|
||||||
|
"github.com/hermeznetwork/hermez-node/log"
|
||||||
"github.com/hermeznetwork/tracerr"
|
"github.com/hermeznetwork/tracerr"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -17,11 +19,45 @@ type Updater struct {
|
|||||||
vars common.SCVariablesPtr
|
vars common.SCVariablesPtr
|
||||||
consts historydb.Constants
|
consts historydb.Constants
|
||||||
rw sync.RWMutex
|
rw sync.RWMutex
|
||||||
|
rfp *RecommendedFeePolicy
|
||||||
|
}
|
||||||
|
|
||||||
|
// RecommendedFeePolicy describes how the recommended fee is calculated
|
||||||
|
type RecommendedFeePolicy struct {
|
||||||
|
PolicyType RecommendedFeePolicyType `validate:"required"`
|
||||||
|
StaticValue float64
|
||||||
|
}
|
||||||
|
|
||||||
|
// RecommendedFeePolicyType describes the different available recommended fee strategies
|
||||||
|
type RecommendedFeePolicyType string
|
||||||
|
|
||||||
|
const (
|
||||||
|
// RecommendedFeePolicyTypeStatic always give the same StaticValue as recommended fee
|
||||||
|
RecommendedFeePolicyTypeStatic RecommendedFeePolicyType = "Static"
|
||||||
|
// RecommendedFeePolicyTypeAvgLastHour set the recommended fee using the average fee of the last hour
|
||||||
|
RecommendedFeePolicyTypeAvgLastHour RecommendedFeePolicyType = "AvgLastHour"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (rfp *RecommendedFeePolicy) valid() bool {
|
||||||
|
switch rfp.PolicyType {
|
||||||
|
case RecommendedFeePolicyTypeStatic:
|
||||||
|
if rfp.StaticValue == 0 {
|
||||||
|
log.Warn("RcommendedFee is set to 0 USD, and the policy is static")
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
case RecommendedFeePolicyTypeAvgLastHour:
|
||||||
|
return true
|
||||||
|
default:
|
||||||
|
return false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewUpdater creates a new Updater
|
// NewUpdater creates a new Updater
|
||||||
func NewUpdater(hdb *historydb.HistoryDB, config *historydb.NodeConfig, vars *common.SCVariables,
|
func NewUpdater(hdb *historydb.HistoryDB, config *historydb.NodeConfig, vars *common.SCVariables,
|
||||||
consts *historydb.Constants) *Updater {
|
consts *historydb.Constants, rfp *RecommendedFeePolicy) (*Updater, error) {
|
||||||
|
if ok := rfp.valid(); !ok {
|
||||||
|
return nil, tracerr.Wrap(fmt.Errorf("Invalid recommended fee policy: %v", rfp.PolicyType))
|
||||||
|
}
|
||||||
u := Updater{
|
u := Updater{
|
||||||
hdb: hdb,
|
hdb: hdb,
|
||||||
config: *config,
|
config: *config,
|
||||||
@@ -31,9 +67,10 @@ func NewUpdater(hdb *historydb.HistoryDB, config *historydb.NodeConfig, vars *co
|
|||||||
ForgeDelay: config.ForgeDelay,
|
ForgeDelay: config.ForgeDelay,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
rfp: rfp,
|
||||||
}
|
}
|
||||||
u.SetSCVars(vars.AsPtr())
|
u.SetSCVars(vars.AsPtr())
|
||||||
return &u
|
return &u, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store the State in the HistoryDB
|
// Store the State in the HistoryDB
|
||||||
@@ -65,6 +102,16 @@ 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 {
|
||||||
|
switch u.rfp.PolicyType {
|
||||||
|
case RecommendedFeePolicyTypeStatic:
|
||||||
|
u.rw.Lock()
|
||||||
|
u.state.RecommendedFee = common.RecommendedFee{
|
||||||
|
ExistingAccount: u.rfp.StaticValue,
|
||||||
|
CreatesAccount: u.rfp.StaticValue,
|
||||||
|
CreatesAccountInternal: u.rfp.StaticValue,
|
||||||
|
}
|
||||||
|
u.rw.Unlock()
|
||||||
|
case RecommendedFeePolicyTypeAvgLastHour:
|
||||||
recommendedFee, err := u.hdb.GetRecommendedFee(u.config.MinFeeUSD, u.config.MaxFeeUSD)
|
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)
|
||||||
@@ -72,6 +119,10 @@ func (u *Updater) UpdateRecommendedFee() error {
|
|||||||
u.rw.Lock()
|
u.rw.Lock()
|
||||||
u.state.RecommendedFee = *recommendedFee
|
u.state.RecommendedFee = *recommendedFee
|
||||||
u.rw.Unlock()
|
u.rw.Unlock()
|
||||||
|
default:
|
||||||
|
return tracerr.New("Invalid recommende fee policy")
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -145,3 +145,11 @@ Coordinator = true
|
|||||||
BatchPath = "/tmp/iden3-test/hermez/batchesdebug"
|
BatchPath = "/tmp/iden3-test/hermez/batchesdebug"
|
||||||
LightScrypt = true
|
LightScrypt = true
|
||||||
# RollupVerifierIndex = 0
|
# RollupVerifierIndex = 0
|
||||||
|
|
||||||
|
[RecommendedFeePolicy]
|
||||||
|
# Strategy used to calculate the recommended fee that the API will expose.
|
||||||
|
# Available options:
|
||||||
|
# - Static: always return the same value (StaticValue) in USD
|
||||||
|
# - AvgLastHour: calculate using the average fee of the forged transactions during the last hour
|
||||||
|
PolicyType = "Static"
|
||||||
|
StaticValue = 0.99
|
||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
|
|
||||||
"github.com/BurntSushi/toml"
|
"github.com/BurntSushi/toml"
|
||||||
ethCommon "github.com/ethereum/go-ethereum/common"
|
ethCommon "github.com/ethereum/go-ethereum/common"
|
||||||
|
"github.com/hermeznetwork/hermez-node/api/stateapiupdater"
|
||||||
"github.com/hermeznetwork/hermez-node/common"
|
"github.com/hermeznetwork/hermez-node/common"
|
||||||
"github.com/hermeznetwork/hermez-node/priceupdater"
|
"github.com/hermeznetwork/hermez-node/priceupdater"
|
||||||
"github.com/hermeznetwork/tracerr"
|
"github.com/hermeznetwork/tracerr"
|
||||||
@@ -347,6 +348,7 @@ type Node struct {
|
|||||||
// can wait to stablish a SQL connection
|
// can wait to stablish a SQL connection
|
||||||
SQLConnectionTimeout Duration
|
SQLConnectionTimeout Duration
|
||||||
} `validate:"required"`
|
} `validate:"required"`
|
||||||
|
RecommendedFeePolicy stateapiupdater.RecommendedFeePolicy `validate:"required"`
|
||||||
Debug NodeDebug `validate:"required"`
|
Debug NodeDebug `validate:"required"`
|
||||||
Coordinator Coordinator `validate:"-"`
|
Coordinator Coordinator `validate:"-"`
|
||||||
}
|
}
|
||||||
|
|||||||
11
node/node.go
11
node/node.go
@@ -288,7 +288,16 @@ func NewNode(mode Mode, cfg *config.Node) (*Node, error) {
|
|||||||
return nil, tracerr.Wrap(err)
|
return nil, tracerr.Wrap(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
stateAPIUpdater := stateapiupdater.NewUpdater(historyDB, &hdbNodeCfg, initSCVars, &hdbConsts)
|
stateAPIUpdater, err := stateapiupdater.NewUpdater(
|
||||||
|
historyDB,
|
||||||
|
&hdbNodeCfg,
|
||||||
|
initSCVars,
|
||||||
|
&hdbConsts,
|
||||||
|
&cfg.RecommendedFeePolicy,
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return nil, tracerr.Wrap(err)
|
||||||
|
}
|
||||||
|
|
||||||
var coord *coordinator.Coordinator
|
var coord *coordinator.Coordinator
|
||||||
if mode == ModeCoordinator {
|
if mode == ModeCoordinator {
|
||||||
|
|||||||
Reference in New Issue
Block a user