mirror of
https://github.com/arnaucube/hermez-node.git
synced 2026-02-07 03:16:45 +01:00
Merge pull request #589 from hermeznetwork/feature/api-batch-timeout
Add forge delay to api get state
This commit is contained in:
@@ -21,6 +21,7 @@ const (
|
||||
// Status define status of the network
|
||||
type Status struct {
|
||||
sync.RWMutex
|
||||
NodeConfig NodeConfig `json:"nodeConfig"`
|
||||
Network Network `json:"network"`
|
||||
Metrics historydb.Metrics `json:"metrics"`
|
||||
Rollup historydb.RollupVariablesAPI `json:"rollup"`
|
||||
@@ -46,6 +47,7 @@ func NewAPI(
|
||||
hdb *historydb.HistoryDB,
|
||||
l2db *l2db.L2DB,
|
||||
config *Config,
|
||||
nodeConfig *NodeConfig,
|
||||
) (*API, error) {
|
||||
// Check input
|
||||
// TODO: is stateDB only needed for explorer endpoints or for both?
|
||||
@@ -64,7 +66,9 @@ func NewAPI(
|
||||
WDelayerConstants: config.WDelayerConstants,
|
||||
},
|
||||
l2: l2db,
|
||||
status: Status{},
|
||||
status: Status{
|
||||
NodeConfig: *nodeConfig,
|
||||
},
|
||||
chainID: config.ChainID,
|
||||
hermezAddress: config.HermezAddress,
|
||||
}
|
||||
|
||||
@@ -237,6 +237,9 @@ func TestMain(m *testing.M) {
|
||||
hdb,
|
||||
l2DB,
|
||||
&_config,
|
||||
&NodeConfig{
|
||||
ForgeDelay: 180,
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@@ -632,6 +635,9 @@ func TestTimeout(t *testing.T) {
|
||||
hdbTO,
|
||||
l2DBTO,
|
||||
&_config,
|
||||
&NodeConfig{
|
||||
ForgeDelay: 180,
|
||||
},
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
|
||||
@@ -24,6 +24,12 @@ type Network struct {
|
||||
NextForgers []NextForger `json:"nextForgers"`
|
||||
}
|
||||
|
||||
// NodeConfig is the configuration of the node that is exposed via API
|
||||
type NodeConfig struct {
|
||||
// ForgeDelay in seconds
|
||||
ForgeDelay float64 `json:"forgeDelay"`
|
||||
}
|
||||
|
||||
// NextForger is a representation of the information of a coordinator and the period will forge
|
||||
type NextForger struct {
|
||||
Coordinator historydb.CoordinatorAPI `json:"coordinator"`
|
||||
|
||||
@@ -2569,6 +2569,21 @@ components:
|
||||
description: List of next coordinators to forge.
|
||||
items:
|
||||
$ref: '#/components/schemas/NextForger'
|
||||
NodeConfig:
|
||||
type: object
|
||||
description: Configuration of the coordinator node. Note that this is specific for each coordinator.
|
||||
properties:
|
||||
forgeDelay:
|
||||
type: number
|
||||
description: |
|
||||
Delay in seconds after which a batch is forged if the slot is
|
||||
already committed. If set to 0s, the coordinator will continuously
|
||||
forge at the maximum rate. Note that this is a configuration parameter of a node,
|
||||
so each coordinator may have a different value.
|
||||
example: 193.4
|
||||
additionalProperties: false
|
||||
required:
|
||||
- forgeDelay
|
||||
State:
|
||||
type: object
|
||||
description: Gobal variables of the network
|
||||
@@ -2585,6 +2600,8 @@ components:
|
||||
$ref: '#/components/schemas/StateWithdrawDelayer'
|
||||
recommendedFee:
|
||||
$ref: '#/components/schemas/RecommendedFee'
|
||||
nodeConfig:
|
||||
$ref: '#/components/schemas/NodeConfig'
|
||||
additionalProperties: false
|
||||
required:
|
||||
- network
|
||||
@@ -2593,6 +2610,7 @@ components:
|
||||
- auction
|
||||
- withdrawalDelayer
|
||||
- recommendedFee
|
||||
- nodeConfig
|
||||
StateNetwork:
|
||||
type: object
|
||||
description: Gobal statistics of the network
|
||||
|
||||
@@ -392,6 +392,7 @@ func NewNode(mode Mode, cfg *config.Node) (*Node, error) {
|
||||
ChainID: chainIDU16,
|
||||
HermezAddress: cfg.SmartContracts.Rollup,
|
||||
},
|
||||
cfg.Coordinator.ForgeDelay.Duration,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, tracerr.Wrap(err)
|
||||
@@ -447,6 +448,7 @@ func NewNodeAPI(
|
||||
sdb *statedb.StateDB,
|
||||
l2db *l2db.L2DB,
|
||||
config *api.Config,
|
||||
forgeDelay time.Duration,
|
||||
) (*NodeAPI, error) {
|
||||
engine := gin.Default()
|
||||
engine.NoRoute(handleNoRoute)
|
||||
@@ -457,6 +459,9 @@ func NewNodeAPI(
|
||||
hdb,
|
||||
l2db,
|
||||
config,
|
||||
&api.NodeConfig{
|
||||
ForgeDelay: forgeDelay.Seconds(),
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
return nil, tracerr.Wrap(err)
|
||||
|
||||
Reference in New Issue
Block a user