mirror of
https://github.com/arnaucube/hermez-node.git
synced 2026-02-07 03:16:45 +01:00
Add Sync stats, and report them in DebugAPI
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
"github.com/hermeznetwork/hermez-node/common"
|
||||
"github.com/hermeznetwork/hermez-node/db/statedb"
|
||||
"github.com/hermeznetwork/hermez-node/log"
|
||||
"github.com/hermeznetwork/hermez-node/synchronizer"
|
||||
)
|
||||
|
||||
func handleNoRoute(c *gin.Context) {
|
||||
@@ -33,13 +34,15 @@ func badReq(err error, c *gin.Context) {
|
||||
type DebugAPI struct {
|
||||
addr string
|
||||
stateDB *statedb.StateDB // synchronizer statedb
|
||||
sync *synchronizer.Synchronizer
|
||||
}
|
||||
|
||||
// NewDebugAPI creates a new DebugAPI
|
||||
func NewDebugAPI(addr string, stateDB *statedb.StateDB) *DebugAPI {
|
||||
func NewDebugAPI(addr string, stateDB *statedb.StateDB, sync *synchronizer.Synchronizer) *DebugAPI {
|
||||
return &DebugAPI{
|
||||
stateDB: stateDB,
|
||||
addr: addr,
|
||||
stateDB: stateDB,
|
||||
sync: sync,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,6 +85,11 @@ func (a *DebugAPI) handleMTRoot(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, root)
|
||||
}
|
||||
|
||||
func (a *DebugAPI) handleSyncStats(c *gin.Context) {
|
||||
stats := a.sync.Stats()
|
||||
c.JSON(http.StatusOK, stats)
|
||||
}
|
||||
|
||||
// Run starts the http server of the DebugAPI. To stop it, pass a context with
|
||||
// cancelation (see `debugapi_test.go` for an example).
|
||||
func (a *DebugAPI) Run(ctx context.Context) error {
|
||||
@@ -98,6 +106,8 @@ func (a *DebugAPI) Run(ctx context.Context) error {
|
||||
debugAPI.GET("sdb/accounts", a.handleAccounts)
|
||||
debugAPI.GET("sdb/accounts/:Idx", a.handleAccount)
|
||||
|
||||
debugAPI.GET("sync/stats", a.handleSyncStats)
|
||||
|
||||
debugAPIServer := &http.Server{
|
||||
Addr: a.addr,
|
||||
Handler: api,
|
||||
|
||||
@@ -50,7 +50,8 @@ func TestDebugAPI(t *testing.T) {
|
||||
require.Nil(t, err)
|
||||
|
||||
addr := "localhost:12345"
|
||||
debugAPI := NewDebugAPI(addr, sdb)
|
||||
// We won't test the sync/stats endpoint, so we can se the Syncrhonizer to nil
|
||||
debugAPI := NewDebugAPI(addr, sdb, nil)
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
go func() {
|
||||
|
||||
@@ -762,6 +762,16 @@ func (c *Client) RollupRegisterTokensCount() (*big.Int, error) {
|
||||
return nil, errTODO
|
||||
}
|
||||
|
||||
// RollupLastForgedBatch is the interface to call the smart contract function
|
||||
func (c *Client) RollupLastForgedBatch() (int64, error) {
|
||||
c.rw.RLock()
|
||||
defer c.rw.RUnlock()
|
||||
|
||||
currentBlock := c.currentBlock()
|
||||
e := currentBlock.Rollup
|
||||
return int64(len(e.State.ExitRoots)) - 1, nil
|
||||
}
|
||||
|
||||
// RollupWithdrawCircuit is the interface to call the smart contract function
|
||||
func (c *Client) RollupWithdrawCircuit(proofA, proofC [2]*big.Int, proofB [2][2]*big.Int, tokenID uint32, numExitRoot, idx int64, amount *big.Int, instantWithdraw bool) (*types.Transaction, error) {
|
||||
log.Error("TODO")
|
||||
|
||||
Reference in New Issue
Block a user