Skip to content

Commit

Permalink
PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
skosito committed Jun 6, 2024
1 parent cca5589 commit 93110fd
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
2 changes: 1 addition & 1 deletion zetaclient/chains/bitcoin/observer/observer.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ func (ob *Observer) GetLastBlockHeight() int64 {
func (ob *Observer) SetLastBlockHeightScanned(height int64) {
atomic.StoreInt64(&ob.lastBlockScanned, height)
// #nosec G701 checked as positive
ob.ts.SetLastScannedBlockNumber((ob.chain.ChainName), uint64(height))
ob.ts.SetLastScannedBlockNumber(ob.chain, uint64(height))

Check warning on line 360 in zetaclient/chains/bitcoin/observer/observer.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/bitcoin/observer/observer.go#L360

Added line #L360 was not covered by tests
}

func (ob *Observer) GetLastBlockHeightScanned() int64 {
Expand Down
2 changes: 1 addition & 1 deletion zetaclient/chains/evm/observer/observer.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ func (ob *Observer) CheckTxInclusion(tx *ethtypes.Transaction, receipt *ethtypes
// SetLastBlockHeightScanned set last block height scanned (not necessarily caught up with external block; could be slow/paused)
func (ob *Observer) SetLastBlockHeightScanned(height uint64) {
atomic.StoreUint64(&ob.lastBlockScanned, height)
ob.ts.SetLastScannedBlockNumber(ob.chain.ChainName, height)
ob.ts.SetLastScannedBlockNumber(ob.chain, height)

Check warning on line 425 in zetaclient/chains/evm/observer/observer.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/evm/observer/observer.go#L425

Added line #L425 was not covered by tests
}

// GetLastBlockHeightScanned get last block height scanned (not necessarily caught up with external block; could be slow/paused)
Expand Down
25 changes: 16 additions & 9 deletions zetaclient/metrics/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ import (
"github.com/zeta-chain/zetacore/zetaclient/types"
)

// TelemetryServer provide http endpoint for Tss server
// TelemetryServer provides http endpoint for Tss server
type TelemetryServer struct {
logger zerolog.Logger
s *http.Server
p2pid string
lastScannedBlockNumber map[string]uint64 // chainName => block number
lastScannedBlockNumber map[int64]uint64 // chainId => block number
lastCoreBlockNumber int64
mu sync.Mutex
lastStartTimestamp time.Time
Expand All @@ -36,7 +36,7 @@ type TelemetryServer struct {
func NewTelemetryServer() *TelemetryServer {
hs := &TelemetryServer{
logger: log.With().Str("module", "http").Logger(),
lastScannedBlockNumber: make(map[string]uint64),
lastScannedBlockNumber: make(map[int64]uint64),
lastStartTimestamp: time.Now(),
HotKeyBurnRate: NewBurnRate(100),

Check warning on line 41 in zetaclient/metrics/telemetry.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/metrics/telemetry.go#L38-L41

Added lines #L38 - L41 were not covered by tests
}
Expand Down Expand Up @@ -78,38 +78,44 @@ func (t *TelemetryServer) GetIPAddress() string {
return t.ipAddress
}

// GetLastStartTimestamp returns last start timestamp
func (t *TelemetryServer) GetLastStartTimestamp() time.Time {
t.mu.Lock()
defer t.mu.Unlock()
return t.lastStartTimestamp

Check warning on line 85 in zetaclient/metrics/telemetry.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/metrics/telemetry.go#L82-L85

Added lines #L82 - L85 were not covered by tests
}

func (t *TelemetryServer) SetLastScannedBlockNumber(chainName chains.ChainName, blockNumber uint64) {
// SetLastScannedBlockNumber last scanned block number for chain in telemetry and metrics
func (t *TelemetryServer) SetLastScannedBlockNumber(chain chains.Chain, blockNumber uint64) {
t.mu.Lock()
t.lastScannedBlockNumber[chainName.String()] = blockNumber
LastScannedBlockNumber.WithLabelValues(chainName.String()).Set(float64(blockNumber))
t.lastScannedBlockNumber[chain.ChainId] = blockNumber
LastScannedBlockNumber.WithLabelValues(chain.ChainName.String()).Set(float64(blockNumber))
t.mu.Unlock()

Check warning on line 93 in zetaclient/metrics/telemetry.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/metrics/telemetry.go#L89-L93

Added lines #L89 - L93 were not covered by tests
}

func (t *TelemetryServer) GetLastScannedBlockNumber(chainName chains.ChainName) uint64 {
// GetLastScannedBlockNumber returns last scanned block number for chain
func (t *TelemetryServer) GetLastScannedBlockNumber(chainId int64) uint64 {

Check warning on line 97 in zetaclient/metrics/telemetry.go

View workflow job for this annotation

GitHub Actions / lint

var-naming: method parameter chainId should be chainID (revive)
t.mu.Lock()
defer t.mu.Unlock()
return t.lastScannedBlockNumber[chainName.String()]
return t.lastScannedBlockNumber[chainId]

Check warning on line 100 in zetaclient/metrics/telemetry.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/metrics/telemetry.go#L97-L100

Added lines #L97 - L100 were not covered by tests
}

// SetCoreBlockNumber sets core block number in telemetry and metrics
func (t *TelemetryServer) SetCoreBlockNumber(blockNumber int64) {
t.mu.Lock()
t.lastCoreBlockNumber = blockNumber
LastCoreBlockNumber.Set(float64(blockNumber))
t.mu.Unlock()

Check warning on line 108 in zetaclient/metrics/telemetry.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/metrics/telemetry.go#L104-L108

Added lines #L104 - L108 were not covered by tests
}

// GetCoreBlockNumber returns core block number
func (t *TelemetryServer) GetCoreBlockNumber() int64 {
t.mu.Lock()
defer t.mu.Unlock()
return t.lastCoreBlockNumber

Check warning on line 115 in zetaclient/metrics/telemetry.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/metrics/telemetry.go#L112-L115

Added lines #L112 - L115 were not covered by tests
}

// SetNumberOfUTXOs sets number of UTXOs in telemetry and metrics
func (t *TelemetryServer) SetNumberOfUTXOs(numberOfUTXOs int) {
t.mu.Lock()
t.status.BTCNumberOfUTXOs = numberOfUTXOs
Expand Down Expand Up @@ -145,6 +151,7 @@ func (t *TelemetryServer) Handlers() http.Handler {
return router
}

// Start starts telemetry server
func (t *TelemetryServer) Start() error {
if t.s == nil {
return errors.New("invalid http server instance")
Expand All @@ -158,6 +165,7 @@ func (t *TelemetryServer) Start() error {
return nil
}

// Stop stops telemetry server
func (t *TelemetryServer) Stop() error {
c, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
Expand Down Expand Up @@ -187,7 +195,6 @@ func (t *TelemetryServer) ipHandler(w http.ResponseWriter, _ *http.Request) {
}

func (t *TelemetryServer) lastScannedBlockHandler(w http.ResponseWriter, _ *http.Request) {
//w.WriteHeader(http.StatusOK)
w.Header().Set("Content-Type", "application/json")

Check warning on line 198 in zetaclient/metrics/telemetry.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/metrics/telemetry.go#L197-L198

Added lines #L197 - L198 were not covered by tests

t.mu.Lock()
Expand Down

0 comments on commit 93110fd

Please sign in to comment.