Browse Source

Add forge delay to api get state

feature/serveapicli
arnaubennassar 3 years ago
parent
commit
54508b0ba6
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
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,
}

+ 6
- 0
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)

+ 6
- 0
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"`

+ 18
- 0
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

+ 5
- 0
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)

Loading…
Cancel
Save