Skip to content

Commit

Permalink
Merge pull request lavanet#40 from lavanet/relayer_errors
Browse files Browse the repository at this point in the history
Some relayer touch ups
  • Loading branch information
omerlavanet authored Jul 6, 2022
2 parents 4e92092 + 5d6ca99 commit 481086d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
13 changes: 7 additions & 6 deletions relayer/chainsentry/chainsentry.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package chainsentry

import (
"context"
"fmt"
"log"
"sync"
"sync/atomic"
Expand Down Expand Up @@ -65,7 +66,6 @@ func (cs *ChainSentry) Init(ctx context.Context) error {
latestBlock, err := cs.fetchLatestBlockNum(ctx)
// TODO:: chekc if we have at least x blocknums before forloop
if err != nil {
log.Fatalln("error: Start", err)
return err
}

Expand All @@ -90,8 +90,7 @@ func (cs *ChainSentry) Init(ctx context.Context) error {
func (cs *ChainSentry) catchupOnFinalizedBlocks(ctx context.Context) error {
latestBlock, err := cs.fetchLatestBlockNum(ctx) // get actual latest from chain
if err != nil {
log.Printf("error: chainSentry block fetcher: %w", err)
return nil // fmt.Errorf("error: chainSentry block fetcher", err)
return fmt.Errorf("error: chainSentry fetchLatestBlockNum: %w", err)
}

if cs.latestBlockNum != latestBlock {
Expand All @@ -106,8 +105,7 @@ func (cs *ChainSentry) catchupOnFinalizedBlocks(ctx context.Context) error {
for ; i <= latestBlock; i++ {
blockHash, err := cs.fetchBlockHashByNum(ctx, i)
if err != nil {
log.Printf("error fetching block hash for block %d: %w", i, err)
return err
return fmt.Errorf("error fetchBlockHashByNum for block %d: %w", i, err)
}

tempArr = append(tempArr, blockHash)
Expand Down Expand Up @@ -135,7 +133,10 @@ func (cs *ChainSentry) Start(ctx context.Context) error {
for {
select {
case <-ticker.C:
cs.catchupOnFinalizedBlocks(ctx)
err := cs.catchupOnFinalizedBlocks(ctx)
if err != nil {
log.Println(err)
}
case <-quit:
ticker.Stop()
return
Expand Down
7 changes: 4 additions & 3 deletions relayer/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ type UserSessions struct {
MaxComputeUnits uint64
DataReliability *pairingtypes.VRFData
VrfPk utils.VrfPubKey
IsBlackListed bool
IsBlockListed bool
}
type RelaySession struct {
userSessionsParent *UserSessions
Expand Down Expand Up @@ -189,7 +189,7 @@ func getOrCreateSession(ctx context.Context, userAddr string, req *pairingtypes.

userSessions := g_sessions[userAddr]

if userSessions.IsBlackListed {
if userSessions.IsBlockListed {
return nil, nil, fmt.Errorf("User blacklisted! userAddr: %s", userAddr)
}

Expand All @@ -208,7 +208,7 @@ func updateSessionCu(sess *RelaySession, serviceApi *spectypes.ServiceApi, reque

// Check that relaynum gets incremented by user
if sess.RelayNum+1 != request.RelayNum {
sess.userSessionsParent.IsBlackListed = true
sess.userSessionsParent.IsBlockListed = true
return fmt.Errorf("consumer requested incorrect relaynum. expected: %d, received: %d", sess.RelayNum+1, request.RelayNum)
}

Expand Down Expand Up @@ -421,6 +421,7 @@ func Server(
err := newSentry.Init(ctx)
if err != nil {
log.Fatalln("error sentry.Init", err)
return
}
go newSentry.Start(ctx)
for newSentry.GetSpecHash() == nil {
Expand Down
4 changes: 2 additions & 2 deletions relayer/test_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func terraTests(ctx context.Context, chainProxy chainproxy.ChainProxy, privKey *

func osmosisTests(ctx context.Context, chainProxy chainproxy.ChainProxy, privKey *btcec.PrivateKey, apiInterface string) {
if apiInterface == "rest" {
for i := 0; i < 10; i++ {
for i := 0; i < 100; i++ {
reply, err := chainproxy.SendRelay(ctx, chainProxy, privKey, TERRA_BLOCKS_LATEST_URL_REST, TERRA_BLOCKS_LATEST_DATA_REST)
if err != nil {
log.Println("1:" + err.Error())
Expand All @@ -179,7 +179,7 @@ func osmosisTests(ctx context.Context, chainProxy chainproxy.ChainProxy, privKey
}
}
} else if apiInterface == "tendermintrpc" {
for i := 0; i < 10; i++ {
for i := 0; i < 100; i++ {
reply, err := chainproxy.SendRelay(ctx, chainProxy, privKey, "", JSONRPC_TERRA_STATUS)
if err != nil {
log.Println(err)
Expand Down

0 comments on commit 481086d

Please sign in to comment.