diff --git a/sequencer/api/api.go b/sequencer/api/api.go deleted file mode 100644 index 2ac910c..0000000 --- a/sequencer/api/api.go +++ /dev/null @@ -1,146 +0,0 @@ -package api - -import ( - "crypto/ecdsa" - "errors" - "tokamak-sybil-resistance/api/coordinatornetwork" - "tokamak-sybil-resistance/common" - "tokamak-sybil-resistance/database/historydb" - "tokamak-sybil-resistance/database/statedb" - - ethCommon "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/ethclient" - "github.com/gin-gonic/gin" - "github.com/go-playground/validator" - "github.com/multiformats/go-multiaddr" -) - -// API serves HTTP requests to allow external interaction with the Hermez node -type API struct { - historyDB *historydb.HistoryDB - config *configAPI - stateDB *statedb.StateDB - hermezAddress ethCommon.Address - validate *validator.Validate - coordnet *coordinatornetwork.CoordinatorNetwork -} - -type CoordinatorNetworkConfig struct { - BootstrapPeers []multiaddr.Multiaddr - EthPrivKey *ecdsa.PrivateKey -} - -// Config wraps the parameters needed to start the API -type Config struct { - Version string - CoordinatorEndpoints bool - ExplorerEndpoints bool - Server *gin.Engine - HistoryDB *historydb.HistoryDB - StateDB *statedb.StateDB - EthClient *ethclient.Client - ForgerAddress *ethCommon.Address - CoordinatorNetworkConfig *CoordinatorNetworkConfig -} - -// NewAPI sets the endpoints and the appropriate handlers, but doesn't start the server -func NewAPI(setup Config) (*API, error) { - // Check input - if setup.ExplorerEndpoints && setup.HistoryDB == nil { - return nil, common.Wrap(errors.New("cannot serve Explorer endpoints without HistoryDB")) - } - consts, err := setup.HistoryDB.GetConstants() - if err != nil { - return nil, err - } - - a := &API{ - historyDB: setup.HistoryDB, - config: &configAPI{ - RollupConstants: *newRollupConstants(consts.Rollup), - ChainID: consts.ChainID, - }, - stateDB: setup.StateDB, - hermezAddress: consts.HermezAddress, - validate: nil, //TODO: Add validations - } - - // Setup coordinator network (libp2p interface) <=TODO - // if setup.CoordinatorNetworkConfig != nil { - // if setup.CoordinatorNetworkConfig.EthPrivKey == nil { - // return nil, tracerr.New("EthPrivateKey is required to setup the coordinators network") - // } - // coordnet, err := coordinatornetwork.NewCoordinatorNetwork( - // setup.CoordinatorNetworkConfig.EthPrivKey, - // setup.CoordinatorNetworkConfig.BootstrapPeers, - // consts.ChainID, - // a.coordnetPoolTxHandler, - // ) - // if err != nil { - // return nil, err - // } - // a.coordnet = &coordnet - // } - - // Setup http interface - // middleware, err := metric.PrometheusMiddleware() - // if err != nil { - // return nil, err - // } - // setup.Server.Use(middleware) - - // setup.Server.NoRoute(a.noRoute) - - // v1 := setup.Server.Group("/v1") - - // v1.GET("/health", gin.WrapH(a.healthRoute(setup.Version, setup.EthClient, setup.ForgerAddress))) - // // Add coordinator endpoints - // if setup.CoordinatorEndpoints { - // // Account creation authorization - // v1.POST("/account-creation-authorization", a.postAccountCreationAuth) - // v1.GET("/account-creation-authorization/:hezEthereumAddress", a.getAccountCreationAuth) - // // Transaction - // v1.POST("/transactions-pool", a.postPoolTx) - // v1.PUT("/transactions-pool/:id", a.putPoolTx) - // v1.PUT("/transactions-pool/accounts/:accountIndex/nonces/:nonce", a.putPoolTxByIdxAndNonce) - // v1.GET("/transactions-pool/:id", a.getPoolTx) - // v1.GET("/transactions-pool", a.getPoolTxs) - // v1.POST("/atomic-pool", a.postAtomicPool) - // v1.GET("/atomic-pool/:id", a.getAtomicGroup) - // } - - // // Add explorer endpoints - // if setup.ExplorerEndpoints { - // // Account - // v1.GET("/accounts", a.getAccounts) - // v1.GET("/accounts/:accountIndex", a.getAccount) - // v1.GET("/exits", a.getExits) - // v1.GET("/exits/:batchNum/:accountIndex", a.getExit) - // // Transaction - // v1.GET("/transactions-history", a.getHistoryTxs) - // v1.GET("/transactions-history/:id", a.getHistoryTx) - // // Batches - // v1.GET("/batches", a.getBatches) - // v1.GET("/batches/:batchNum", a.getBatch) - // v1.GET("/full-batches/:batchNum", a.getFullBatch) - // // Slots - // v1.GET("/slots", a.getSlots) - // v1.GET("/slots/:slotNum", a.getSlot) - // // Bids - // v1.GET("/bids", a.getBids) - // // State - // v1.GET("/state", a.getState) - // // Config - // v1.GET("/config", a.getConfig) - // // Tokens - // v1.GET("/tokens", a.getTokens) - // v1.GET("/tokens/:id", a.getToken) - // // Fiat Currencies - // v1.GET("/currencies", a.getFiatCurrencies) - // v1.GET("/currencies/:symbol", a.getFiatCurrency) - // // Coordinators - // v1.GET("/coordinators", a.getCoordinators) - // } - - return a, nil -} diff --git a/sequencer/api/config.go b/sequencer/api/config.go deleted file mode 100644 index a691d23..0000000 --- a/sequencer/api/config.go +++ /dev/null @@ -1,46 +0,0 @@ -package api - -import ( - "math/big" - "tokamak-sybil-resistance/common" -) - -type rollupConstants struct { - PublicConstants common.RollupConstants `json:"publicConstants"` - // MaxFeeIdxCoordinator int `json:"maxFeeIdxCoordinator"` - ReservedIdx int `json:"reservedIdx"` - ExitIdx int `json:"exitIdx"` - LimitDepositAmount *big.Int `json:"limitDepositAmount"` - LimitTokens int `json:"limitTokens"` - L1CoordinatorTotalBytes int `json:"l1CoordinatorTotalBytes"` - L1UserTotalBytes int `json:"l1UserTotalBytes"` - MaxL1UserTx int `json:"maxL1UserTx"` - MaxL1Tx int `json:"maxL1Tx"` - InputSHAConstantBytes int `json:"inputSHAConstantBytes"` - NumBuckets int `json:"numBuckets"` - // MaxWithdrawalDelay int `json:"maxWithdrawalDelay"` - ExchangeMultiplier int `json:"exchangeMultiplier"` -} - -type configAPI struct { - ChainID uint64 `json:"chainId"` - RollupConstants rollupConstants `json:"hermez"` -} - -func newRollupConstants(publicConstants common.RollupConstants) *rollupConstants { - return &rollupConstants{ - PublicConstants: publicConstants, - // MaxFeeIdxCoordinator: common.RollupConstMaxFeeIdxCoordinator, - ReservedIdx: common.RollupConstReservedIDx, - ExitIdx: common.RollupConstExitIDx, - LimitDepositAmount: common.RollupConstLimitDepositAmount, - LimitTokens: common.RollupConstLimitTokens, - L1CoordinatorTotalBytes: common.RollupConstL1CoordinatorTotalBytes, - L1UserTotalBytes: common.RollupConstL1UserTotalBytes, - MaxL1UserTx: common.RollupConstMaxL1UserTx, - MaxL1Tx: common.RollupConstMaxL1Tx, - InputSHAConstantBytes: common.RollupConstInputSHAConstantBytes, - // MaxWithdrawalDelay: common.RollupConstMaxWithdrawalDelay, - ExchangeMultiplier: common.RollupConstExchangeMultiplier, - } -} diff --git a/sequencer/api/coordinatornetwork/coordinatornetwork.go b/sequencer/api/coordinatornetwork/coordinatornetwork.go deleted file mode 100644 index 114ac20..0000000 --- a/sequencer/api/coordinatornetwork/coordinatornetwork.go +++ /dev/null @@ -1,27 +0,0 @@ -/* -Package coordinatornetwork implements a comunication layer among coordinators -in order to share information such as transactions in the pool and create account authorizations. - -To do so the pubsub gossip protocol is used. -This code is currently heavily based on this example: https://github.com/libp2p/go-libp2p/blob/master/examples/pubsub -*/ - -package coordinatornetwork - -import ( - "context" - - "github.com/libp2p/go-libp2p-core/host" - discovery "github.com/libp2p/go-libp2p-discovery" - dht "github.com/libp2p/go-libp2p-kad-dht" -) - -// CoordinatorNetwork it's a p2p communication layer that enables coordinators to exchange information -// in benefit of the network and them selfs. The main goal is to share L2 data (common.PoolL2Tx and common.AccountCreationAuth) -type CoordinatorNetwork struct { - self host.Host - dht *dht.IpfsDHT - ctx context.Context - discovery *discovery.RoutingDiscovery - discoveryServiceTag string -} diff --git a/sequencer/api/stateapiupdater/stateapiupdater.go b/sequencer/api/stateapiupdater/stateapiupdater.go deleted file mode 100644 index 069834a..0000000 --- a/sequencer/api/stateapiupdater/stateapiupdater.go +++ /dev/null @@ -1,181 +0,0 @@ -/* -Package stateapiupdater is responsible for generating and storing the object response of the GET /state endpoint exposed through the api package. -This object is extensively defined at the OpenAPI spec located at api/swagger.yml. - -Deployment considerations: in a setup where multiple processes are used (dedicated api process, separated coord / sync, ...), only one process should care -of using this package. -*/ -package stateapiupdater - -import ( - "database/sql" - "sync" - "tokamak-sybil-resistance/common" - "tokamak-sybil-resistance/database/historydb" - "tokamak-sybil-resistance/log" -) - -// Updater is an utility object to facilitate updating the StateAPI -type Updater struct { - hdb *historydb.HistoryDB - state historydb.StateAPI - config historydb.NodeConfig - vars common.SCVariablesPtr - consts historydb.Constants - rw sync.RWMutex - maxTxPerBatch int64 -} - -// RecommendedFeePolicy describes how the recommended fee is calculated -type RecommendedFeePolicy struct { - PolicyType RecommendedFeePolicyType `validate:"required" env:"HEZNODE_RECOMMENDEDFEEPOLICY_POLICYTYPE"` - StaticValue float64 `env:"HEZNODE_RECOMMENDEDFEEPOLICY_STATICVALUE"` - BreakThreshold int `env:"HEZNODE_RECOMMENDEDFEEPOLICY_BREAKTHRESHOLD"` - NumLastBatchAvg int `env:"HEZNODE_RECOMMENDEDFEEPOLICY_NUMLASTBATCHAVG"` -} - -// RecommendedFeePolicyType describes the different available recommended fee strategies -type RecommendedFeePolicyType string - -const ( - // RecommendedFeePolicyTypeStatic always give the same StaticValue as recommended fee - RecommendedFeePolicyTypeStatic RecommendedFeePolicyType = "Static" - // RecommendedFeePolicyTypeAvgLastHour set the recommended fee using the average fee of the last hour - RecommendedFeePolicyTypeAvgLastHour RecommendedFeePolicyType = "AvgLastHour" - // RecommendedFeePolicyTypeDynamicFee set the recommended fee taking in account the gas used in L1, - // the gasPrice and the ether price in the last batches - RecommendedFeePolicyTypeDynamicFee RecommendedFeePolicyType = "DynamicFee" -) - -func (rfp *RecommendedFeePolicy) valid() bool { - switch rfp.PolicyType { - case RecommendedFeePolicyTypeStatic: - if rfp.StaticValue == 0 { - log.Warn("RecommendedFee is set to 0 USD, and the policy is static") - } - return true - case RecommendedFeePolicyTypeAvgLastHour: - return true - case RecommendedFeePolicyTypeDynamicFee: - return true - default: - return false - } -} - -// SetSCVars sets the smart contract vars (ony updates those that are not nil) -func (u *Updater) SetSCVars(vars *common.SCVariablesPtr) { - u.rw.Lock() - defer u.rw.Unlock() - if vars.Rollup != nil { - u.vars.Rollup = vars.Rollup - rollupVars := historydb.NewRollupVariablesAPI(u.vars.Rollup) - u.state.Rollup = *rollupVars - } - // if vars.Auction != nil { - // u.vars.Auction = vars.Auction - // auctionVars := historydb.NewAuctionVariablesAPI(u.vars.Auction) - // u.state.Auction = *auctionVars - // } - // if vars.WDelayer != nil { - // u.vars.WDelayer = vars.WDelayer - // u.state.WithdrawalDelayer = *u.vars.WDelayer - // } -} - -// NewUpdater creates a new Updater -func NewUpdater( - hdb *historydb.HistoryDB, - config *historydb.NodeConfig, - vars *common.SCVariables, - consts *historydb.Constants, - // rfp *RecommendedFeePolicy, - maxTxPerBatch int64, -) (*Updater, error) { - u := Updater{ - hdb: hdb, - config: *config, - consts: *consts, - state: historydb.StateAPI{ - NodePublicInfo: historydb.NodePublicInfo{ - ForgeDelay: config.ForgeDelay, - }, - }, - maxTxPerBatch: maxTxPerBatch, - } - u.SetSCVars(vars.AsPtr()) - return &u, nil -} - -// Store the State in the HistoryDB -func (u *Updater) Store() error { - u.rw.RLock() - defer u.rw.RUnlock() - return common.Wrap(u.hdb.SetStateInternalAPI(&u.state)) -} - -// UpdateNetworkInfo update Status.Network information -func (u *Updater) UpdateNetworkInfo( - lastEthBlock, lastSyncBlock common.Block, - lastBatchNum common.BatchNum, /*, currentSlot int64*/ -) error { - // Get last batch in API format - lastBatch, err := u.hdb.GetBatchInternalAPI(lastBatchNum) - if common.Unwrap(err) == sql.ErrNoRows { - lastBatch = nil - } else if err != nil { - return common.Wrap(err) - } - // u.rw.RLock() - // auctionVars := u.vars.Auction - // u.rw.RUnlock() - // Get next forgers - // lastClosedSlot := currentSlot + int64(auctionVars.ClosedAuctionSlots) - // nextForgers, err := u.hdb.GetNextForgersInternalAPI(auctionVars, &u.consts.Auction, - // lastSyncBlock, currentSlot, lastClosedSlot) - // if common.Unwrap(err) == sql.ErrNoRows { - // nextForgers = nil - // } else if err != nil { - // return common.Wrap(err) - // } - - bucketUpdates, err := u.hdb.GetBucketUpdatesInternalAPI() - if err == sql.ErrNoRows { - bucketUpdates = nil - } else if err != nil { - return common.Wrap(err) - } - - u.rw.Lock() - // Update NodeInfo struct - for i, bucketParams := range u.state.Rollup.Buckets { - for _, bucketUpdate := range bucketUpdates { - if bucketUpdate.NumBucket == i { - bucketParams.Withdrawals = bucketUpdate.Withdrawals - u.state.Rollup.Buckets[i] = bucketParams - break - } - } - } - // Update pending L1s - pendingL1s, err := u.hdb.GetUnforgedL1UserTxsCount() - if err != nil { - return common.Wrap(err) - } - u.state.Network.LastSyncBlock = lastSyncBlock.Num - u.state.Network.LastEthBlock = lastEthBlock.Num - u.state.Network.LastBatch = lastBatch - // u.state.Network.CurrentSlot = currentSlot - // u.state.Network.NextForgers = nextForgers - u.state.Network.PendingL1Txs = pendingL1s - u.rw.Unlock() - return nil -} - -// UpdateNetworkInfoBlock update Status.Network block related information -func (u *Updater) UpdateNetworkInfoBlock(lastEthBlock, lastSyncBlock common.Block) { - u.rw.Lock() - u.state.Network.LastSyncBlock = lastSyncBlock.Num - u.state.Network.LastEthBlock = lastEthBlock.Num - u.rw.Unlock() -} diff --git a/sequencer/node/node.go b/sequencer/node/node.go index 6a59c34..74bcd58 100644 --- a/sequencer/node/node.go +++ b/sequencer/node/node.go @@ -18,7 +18,6 @@ import ( "os" "sync" "time" - "tokamak-sybil-resistance/api/stateapiupdater" "tokamak-sybil-resistance/batchbuilder" "tokamak-sybil-resistance/common" "tokamak-sybil-resistance/config" @@ -48,9 +47,6 @@ const RollupStartBlockNum = 379608 // Node is the Hermez Node type Node struct { - // nodeAPI *NodeAPI - stateAPIUpdater *stateapiupdater.Updater - // debugAPI *debugapi.DebugAPI // Coordinator coord *coordinator.Coordinator @@ -68,49 +64,6 @@ type Node struct { cancel context.CancelFunc } -// APIServer is a server that only runs the API -// type APIServer struct { -// nodeAPI *NodeAPI -// mode Mode -// ctx context.Context -// wg sync.WaitGroup -// cancel context.CancelFunc -// } - -// NodeAPI holds the node http API -// type NodeAPI struct { //nolint:golint -// api *api.API -// engine *gin.Engine -// addr string -// coordinatorNetwork bool -// coordinatorNetworkFindMorePeersInterval time.Duration -// readtimeout time.Duration -// writetimeout time.Duration -// } - -// NewNodeAPI creates a new NodeAPI (which internally calls api.NewAPI) -// func NewNodeAPI( -// addr string, -// cfgAPI config.APIConfigParameters, -// apiConfig api.Config, -// coordinatorNetwork bool, -// coordinatorNetworkFindMorePeersInterval time.Duration, -// ) (*NodeAPI, error) { -// _api, err := api.NewAPI(apiConfig) -// if err != nil { -// return nil, common.Wrap(err) -// } -// return &NodeAPI{ -// addr: addr, -// api: _api, -// engine: apiConfig.Server, -// coordinatorNetwork: coordinatorNetwork, -// coordinatorNetworkFindMorePeersInterval: coordinatorNetworkFindMorePeersInterval, -// readtimeout: cfgAPI.Readtimeout.Duration, -// writetimeout: cfgAPI.Writetimeout.Duration, -// }, nil -// } - // Check if a directory exists and is empty func isDirectoryEmpty(path string) (bool, error) { dirEntries, err := os.ReadDir(path) @@ -306,16 +259,6 @@ func NewNode(cfg *config.Node, version string) (*Node, error) { log.Info("EtherScan method not configured in config file") etherScanService = nil } - stateAPIUpdater, err := stateapiupdater.NewUpdater( - historyDB, - &hdbNodeCfg, - initSCVars, - &hdbConsts, - cfg.Coordinator.Circuit.MaxTx, - ) - if err != nil { - return nil, common.Wrap(err) - } var coord *coordinator.Coordinator @@ -389,78 +332,17 @@ func NewNode(cfg *config.Node, version string) (*Node, error) { if err != nil { return nil, common.Wrap(err) } - // } - // var nodeAPI *NodeAPI - // if cfg.API.Address != "" { - // if cfg.Debug.GinDebugMode { - // gin.SetMode(gin.DebugMode) - // } else { - // gin.SetMode(gin.ReleaseMode) - // } - // server := gin.Default() - // server.Use(cors.Default()) - // coord := false - // var coordnetConfig *api.CoordinatorNetworkConfig - // if mode == ModeCoordinator { - // coord = cfg.Coordinator.API.Coordinator - // if cfg.API.CoordinatorNetwork { - // // Setup coordinators network configuration - // // Get libp2p addresses of the registered coordinators - // // to be used as bootstrap nodes for the p2p network - - // //TODO: Check if we'll need this - // // bootstrapAddrs, err := client.GetCoordinatorsLibP2PAddrs() - // if err != nil { - // log.Warn("error getting registered addresses from the SMC or no addresses registered. error:", err.Error()) - // } - // // Get Ethereum private key of the coordinator - // keyJSON, err := keyStore.Export(*account, keystorePassword, keystorePassword) - // if err != nil { - // return nil, common.Wrap(err) - // } - // key, err := keystore.DecryptKey(keyJSON, keystorePassword) - // if err != nil { - // return nil, common.Wrap(err) - // } - // coordnetConfig = &api.CoordinatorNetworkConfig{ - // BootstrapPeers: nil, - // EthPrivKey: key.PrivateKey, - // } - // } - // } - // var err error - // nodeAPI, err = NewNodeAPI(cfg.API.Address, cfg.API, api.Config{ - // Version: version, - // ExplorerEndpoints: cfg.API.Explorer, - // CoordinatorEndpoints: coord, - // Server: server, - // HistoryDB: historyDB, - // StateDB: stateDB, - // EthClient: ethClient, - // ForgerAddress: &forgerAddress, - // CoordinatorNetworkConfig: coordnetConfig, - // }, cfg.API.CoordinatorNetwork, cfg.API.FindPeersCoordinatorNetworkInterval.Duration) - // if err != nil { - // return nil, common.Wrap(err) - // } - // } - // TODO: Update debug API fields - // var debugAPI *debugapi.DebugAPI - // if cfg.Debug.APIAddress != "" { - // debugAPI = debugapi.NewDebugAPI(cfg.Debug.APIAddress, stateDB, sync) - // } ctx, cancel := context.WithCancel(context.Background()) return &Node{ - stateAPIUpdater: stateAPIUpdater, - coord: coord, - sync: sync, - cfg: cfg, - sqlConnRead: db, - sqlConnWrite: db, - historyDB: historyDB, - ctx: ctx, - cancel: cancel, + coord: coord, + sync: sync, + cfg: cfg, + sqlConnRead: db, + sqlConnWrite: db, + historyDB: historyDB, + ctx: ctx, + cancel: cancel, }, nil } @@ -468,19 +350,24 @@ func (n *Node) handleReorg( ctx context.Context, stats *synchronizer.Stats, vars *common.SCVariables, -) error { +) { n.coord.SendMsg(ctx, coordinator.MsgSyncReorg{ Stats: *stats, Vars: *vars.AsPtr(), }) - n.stateAPIUpdater.SetSCVars(vars.AsPtr()) - n.stateAPIUpdater.UpdateNetworkInfoBlock( - stats.Eth.LastBlock, stats.Sync.LastBlock, - ) - if err := n.stateAPIUpdater.Store(); err != nil { - return common.Wrap(err) - } - return nil +} + +func (n *Node) handleNewBlock( + ctx context.Context, + stats *synchronizer.Stats, + vars *common.SCVariablesPtr, + batches []common.BatchData, +) { + n.coord.SendMsg(ctx, coordinator.MsgSyncBlock{ + Stats: *stats, + Vars: *vars, + Batches: batches, + }) } func (n *Node) syncLoopFn(ctx context.Context, lastBlock *common.Block) (*common.Block, @@ -494,18 +381,15 @@ func (n *Node) syncLoopFn(ctx context.Context, lastBlock *common.Block) (*common // case: reorg log.Infow("Synchronizer.Sync reorg", "discarded", *discarded) vars := n.sync.SCVars() - if err := n.handleReorg(ctx, stats, vars); err != nil { - return nil, time.Duration(0), common.Wrap(err) - } + n.handleReorg(ctx, stats, vars) + return nil, time.Duration(0), nil } else if blockData != nil { // case: new block vars := common.SCVariablesPtr{ Rollup: blockData.Rollup.Vars, } - if err := n.handleNewBlock(ctx, stats, &vars); err != nil { - return nil, time.Duration(SyncTime), common.Wrap(err) - } + n.handleNewBlock(ctx, stats, &vars, blockData.Rollup.Batches) return &blockData.Block, time.Duration(SyncTime), nil } else { // case: no block @@ -524,9 +408,7 @@ func (n *Node) StartSynchronizer() { // the last synced one) is synchronized stats := n.sync.Stats() vars := n.sync.SCVars() - if err := n.handleNewBlock(n.ctx, stats, vars.AsPtr() /*, []common.BatchData{}*/); err != nil { - log.Fatalw("Node.handleNewBlock", "err", err) - } + n.handleNewBlock(n.ctx, stats, vars.AsPtr(), []common.BatchData{}) n.wg.Add(1) go func() { @@ -580,42 +462,3 @@ func (n *Node) Stop() { n.coord.TxSelector().LocalAccountsDB().Close() n.coord.BatchBuilder().LocalStateDB().Close() } - -func (n *Node) handleNewBlock( - ctx context.Context, - stats *synchronizer.Stats, - vars *common.SCVariablesPtr, - /*, batches []common.BatchData*/ -) error { - n.coord.SendMsg(ctx, coordinator.MsgSyncBlock{ - Stats: *stats, - Vars: *vars, - }) - n.stateAPIUpdater.SetSCVars(vars) - - /* - When the state is out of sync, which means, the last block synchronized by the node is - different/smaller from the last block provided by the ethereum, the network info in the state - will not be updated. So, in order to get some information on the node state, we need - to wait until the node finish the synchronization with the ethereum network. - - Side effects are information like lastBatch, nextForgers, metrics with zeros, defaults or null values - */ - if stats.Synced() { - if err := n.stateAPIUpdater.UpdateNetworkInfo( - stats.Eth.LastBlock, stats.Sync.LastBlock, - common.BatchNum(stats.Eth.LastBatchNum), - // stats.Sync.Auction.CurrentSlot.SlotNum, - ); err != nil { - log.Errorw("ApiStateUpdater.UpdateNetworkInfo", "err", err) - } - } else { - n.stateAPIUpdater.UpdateNetworkInfoBlock( - stats.Eth.LastBlock, stats.Sync.LastBlock, - ) - } - if err := n.stateAPIUpdater.Store(); err != nil { - return common.Wrap(err) - } - return nil -}