-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Log sync heights of blockchain and storage node. * Regen swagger doc.
- Loading branch information
Showing
11 changed files
with
173 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package stat | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"sync" | ||
"time" | ||
|
||
viperutil "github.com/Conflux-Chain/go-conflux-util/viper" | ||
"github.com/pkg/errors" | ||
"github.com/sirupsen/logrus" | ||
"github.com/zero-gravity-labs/zerog-storage-client/node" | ||
"github.com/zero-gravity-labs/zerog-storage-scan/store" | ||
"gorm.io/gorm" | ||
) | ||
|
||
type LogSyncInfoStat struct { | ||
db *store.MysqlStore | ||
l2Sdk *node.Client | ||
interval time.Duration | ||
} | ||
|
||
func MustNewSyncStatusStat(db *store.MysqlStore, l2Sdk *node.Client) *LogSyncInfoStat { | ||
var stat struct { | ||
StatIntervalSyncStatus time.Duration `default:"1s"` | ||
} | ||
viperutil.MustUnmarshalKey("stat", &stat) | ||
|
||
return &LogSyncInfoStat{ | ||
db: db, | ||
l2Sdk: l2Sdk, | ||
interval: stat.StatIntervalSyncStatus, | ||
} | ||
} | ||
|
||
func (s *LogSyncInfoStat) DoStat(ctx context.Context, wg *sync.WaitGroup) { | ||
wg.Add(1) | ||
defer wg.Done() | ||
logrus.Info("Stat log sync info starting") | ||
|
||
for { | ||
select { | ||
case <-ctx.Done(): | ||
return | ||
default: | ||
} | ||
|
||
var submit store.Submit | ||
err := s.db.Store.DB.Last(&submit).Error | ||
if errors.Is(err, gorm.ErrRecordNotFound) { | ||
logrus.WithError(err).Info("No submit record to update log sync info") | ||
time.Sleep(10 * time.Second) | ||
continue | ||
} | ||
if err != nil { | ||
logrus.WithError(err).Error("Failed to get submit record to update log sync info") | ||
time.Sleep(10 * time.Second) | ||
continue | ||
} | ||
|
||
zgStatus, err := s.l2Sdk.ZeroGStorage().GetStatus() | ||
if err != nil { | ||
logrus.WithError(err).Error("Failed to get zg status to update log sync info") | ||
time.Sleep(10 * time.Second) | ||
continue | ||
} | ||
|
||
status := LogSyncInfo{ | ||
LogSyncHeight: submit.BlockNumber, | ||
L2LogSyncHeight: zgStatus.LogSyncHeight, | ||
} | ||
statusBytes, err := json.Marshal(status) | ||
if err != nil { | ||
logrus.WithError(err).Error("Failed to marshal log sync info") | ||
continue | ||
} | ||
|
||
if err := s.db.ConfigStore.Upsert(store.KeyLogSyncInfo, string(statusBytes)); err != nil { | ||
logrus.WithError(err).Error("Update log sync info error.") | ||
time.Sleep(10 * time.Second) | ||
continue | ||
} | ||
|
||
time.Sleep(s.interval) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package stat | ||
|
||
type LogSyncInfo struct { | ||
LogSyncHeight uint64 `json:"logSyncHeight"` | ||
L2LogSyncHeight uint64 `json:"l2LogSyncHeight"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters