Merge pull request #589 from hermeznetwork/feature/api-batch-timeout Add forge delay to api get state
Alberto Elias hi@albertoelias.me
Fri, 26 Feb 2021 11:44:20 +0000
5 files changed,
41 insertions(+),
2 deletions(-)
M
api/api.go
→
api/api.go
@@ -21,6 +21,7 @@
// 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 @@ server *gin.Engine,
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?@@ -63,8 +65,10 @@ RollupConstants: *newRollupConstants(config.RollupConstants),
AuctionConstants: config.AuctionConstants, WDelayerConstants: config.WDelayerConstants, }, - l2: l2db, - status: Status{}, + l2: l2db, + status: Status{ + NodeConfig: *nodeConfig, + }, chainID: config.ChainID, hermezAddress: config.HermezAddress, }
M
api/api_test.go
→
api/api_test.go
@@ -237,6 +237,9 @@ apiGin,
hdb, l2DB, &_config, + &NodeConfig{ + ForgeDelay: 180, + }, ) if err != nil { panic(err)@@ -632,6 +635,9 @@ apiGinTO,
hdbTO, l2DBTO, &_config, + &NodeConfig{ + ForgeDelay: 180, + }, ) require.NoError(t, err)
M
api/state.go
→
api/state.go
@@ -24,6 +24,12 @@ CurrentSlot int64 `json:"currentSlot"`
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"`
M
api/swagger.yml
→
api/swagger.yml
@@ -2569,6 +2569,21 @@ type: array
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 @@ withdrawalDelayer:
$ref: '#/components/schemas/StateWithdrawDelayer' recommendedFee: $ref: '#/components/schemas/RecommendedFee' + nodeConfig: + $ref: '#/components/schemas/NodeConfig' additionalProperties: false required: - network@@ -2593,6 +2610,7 @@ - rollup
- auction - withdrawalDelayer - recommendedFee + - nodeConfig StateNetwork: type: object description: Gobal statistics of the network
M
node/node.go
→
node/node.go
@@ -392,6 +392,7 @@ WDelayerConstants: scConsts.WDelayer,
ChainID: chainIDU16, HermezAddress: cfg.SmartContracts.Rollup, }, + cfg.Coordinator.ForgeDelay.Duration, ) if err != nil { return nil, tracerr.Wrap(err)@@ -447,6 +448,7 @@ hdb *historydb.HistoryDB,
sdb *statedb.StateDB, l2db *l2db.L2DB, config *api.Config, + forgeDelay time.Duration, ) (*NodeAPI, error) { engine := gin.Default() engine.NoRoute(handleNoRoute)@@ -457,6 +459,9 @@ engine,
hdb, l2db, config, + &api.NodeConfig{ + ForgeDelay: forgeDelay.Seconds(), + }, ) if err != nil { return nil, tracerr.Wrap(err)