Browse Source

Merge pull request #589 from hermeznetwork/feature/api-batch-timeout

Add forge delay to api get state
feature/serveapicli
Alberto Elias 3 years ago
committed by GitHub
parent
commit
91c96eb429
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 41 additions and 2 deletions
  1. +6
    -2
      api/api.go
  2. +6
    -0
      api/api_test.go
  3. +6
    -0
      api/state.go
  4. +18
    -0
      api/swagger.yml
  5. +5
    -0
      node/node.go

+ 6
- 2
api/api.go

@ -21,6 +21,7 @@ const (
// Status define status of the network // Status define status of the network
type Status struct { type Status struct {
sync.RWMutex sync.RWMutex
NodeConfig NodeConfig `json:"nodeConfig"`
Network Network `json:"network"` Network Network `json:"network"`
Metrics historydb.Metrics `json:"metrics"` Metrics historydb.Metrics `json:"metrics"`
Rollup historydb.RollupVariablesAPI `json:"rollup"` Rollup historydb.RollupVariablesAPI `json:"rollup"`
@ -46,6 +47,7 @@ func NewAPI(
hdb *historydb.HistoryDB, hdb *historydb.HistoryDB,
l2db *l2db.L2DB, l2db *l2db.L2DB,
config *Config, config *Config,
nodeConfig *NodeConfig,
) (*API, error) { ) (*API, error) {
// Check input // Check input
// TODO: is stateDB only needed for explorer endpoints or for both? // TODO: is stateDB only needed for explorer endpoints or for both?
@ -63,8 +65,10 @@ func NewAPI(
AuctionConstants: config.AuctionConstants, AuctionConstants: config.AuctionConstants,
WDelayerConstants: config.WDelayerConstants, WDelayerConstants: config.WDelayerConstants,
}, },
l2: l2db,
status: Status{},
l2: l2db,
status: Status{
NodeConfig: *nodeConfig,
},
chainID: config.ChainID, chainID: config.ChainID,
hermezAddress: config.HermezAddress, hermezAddress: config.HermezAddress,
} }

+ 6
- 0
api/api_test.go

@ -237,6 +237,9 @@ func TestMain(m *testing.M) {
hdb, hdb,
l2DB, l2DB,
&_config, &_config,
&NodeConfig{
ForgeDelay: 180,
},
) )
if err != nil { if err != nil {
panic(err) panic(err)
@ -632,6 +635,9 @@ func TestTimeout(t *testing.T) {
hdbTO, hdbTO,
l2DBTO, l2DBTO,
&_config, &_config,
&NodeConfig{
ForgeDelay: 180,
},
) )
require.NoError(t, err) require.NoError(t, err)

+ 6
- 0
api/state.go

@ -24,6 +24,12 @@ type Network struct {
NextForgers []NextForger `json:"nextForgers"` 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 // NextForger is a representation of the information of a coordinator and the period will forge
type NextForger struct { type NextForger struct {
Coordinator historydb.CoordinatorAPI `json:"coordinator"` Coordinator historydb.CoordinatorAPI `json:"coordinator"`

+ 18
- 0
api/swagger.yml

@ -2569,6 +2569,21 @@ 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:
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: State:
type: object type: object
description: Gobal variables of the network description: Gobal variables of the network
@ -2585,6 +2600,8 @@ components:
$ref: '#/components/schemas/StateWithdrawDelayer' $ref: '#/components/schemas/StateWithdrawDelayer'
recommendedFee: recommendedFee:
$ref: '#/components/schemas/RecommendedFee' $ref: '#/components/schemas/RecommendedFee'
nodeConfig:
$ref: '#/components/schemas/NodeConfig'
additionalProperties: false additionalProperties: false
required: required:
- network - network
@ -2593,6 +2610,7 @@ components:
- auction - auction
- withdrawalDelayer - withdrawalDelayer
- recommendedFee - recommendedFee
- nodeConfig
StateNetwork: StateNetwork:
type: object type: object
description: Gobal statistics of the network description: Gobal statistics of the network

+ 5
- 0
node/node.go

@ -392,6 +392,7 @@ func NewNode(mode Mode, cfg *config.Node) (*Node, error) {
ChainID: chainIDU16, ChainID: chainIDU16,
HermezAddress: cfg.SmartContracts.Rollup, HermezAddress: cfg.SmartContracts.Rollup,
}, },
cfg.Coordinator.ForgeDelay.Duration,
) )
if err != nil { if err != nil {
return nil, tracerr.Wrap(err) return nil, tracerr.Wrap(err)
@ -447,6 +448,7 @@ func NewNodeAPI(
sdb *statedb.StateDB, sdb *statedb.StateDB,
l2db *l2db.L2DB, l2db *l2db.L2DB,
config *api.Config, config *api.Config,
forgeDelay time.Duration,
) (*NodeAPI, error) { ) (*NodeAPI, error) {
engine := gin.Default() engine := gin.Default()
engine.NoRoute(handleNoRoute) engine.NoRoute(handleNoRoute)
@ -457,6 +459,9 @@ func NewNodeAPI(
hdb, hdb,
l2db, l2db,
config, config,
&api.NodeConfig{
ForgeDelay: forgeDelay.Seconds(),
},
) )
if err != nil { if err != nil {
return nil, tracerr.Wrap(err) return nil, tracerr.Wrap(err)

Loading…
Cancel
Save