From 54508b0ba635aeea2f47176ddc854a2934c60582 Mon Sep 17 00:00:00 2001 From: arnaubennassar Date: Fri, 26 Feb 2021 11:40:09 +0100 Subject: [PATCH] Add forge delay to api get state --- api/api.go | 8 ++++++-- api/api_test.go | 6 ++++++ api/state.go | 6 ++++++ api/swagger.yml | 18 ++++++++++++++++++ node/node.go | 5 +++++ 5 files changed, 41 insertions(+), 2 deletions(-) diff --git a/api/api.go b/api/api.go index b6a9764..631d76e 100644 --- a/api/api.go +++ b/api/api.go @@ -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? @@ -63,8 +65,10 @@ func NewAPI( AuctionConstants: config.AuctionConstants, WDelayerConstants: config.WDelayerConstants, }, - l2: l2db, - status: Status{}, + l2: l2db, + status: Status{ + NodeConfig: *nodeConfig, + }, chainID: config.ChainID, hermezAddress: config.HermezAddress, } diff --git a/api/api_test.go b/api/api_test.go index a30ca27..b321fb1 100644 --- a/api/api_test.go +++ b/api/api_test.go @@ -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) diff --git a/api/state.go b/api/state.go index f5448ce..eecdd77 100644 --- a/api/state.go +++ b/api/state.go @@ -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"` diff --git a/api/swagger.yml b/api/swagger.yml index 58b5911..3b38d93 100644 --- a/api/swagger.yml +++ b/api/swagger.yml @@ -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 diff --git a/node/node.go b/node/node.go index 56c4d12..33ec3b8 100644 --- a/node/node.go +++ b/node/node.go @@ -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)