Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
cam-schultz committed Sep 5, 2023
1 parent ebdfc79 commit 532094c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
5 changes: 3 additions & 2 deletions database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ const (
)

var (
ErrKeyNotFound = errors.New("key not found")
ErrChainNotFound = errors.New("no database for chain")
ErrKeyNotFound = errors.New("key not found")
ErrChainNotFound = errors.New("no database for chain")
ErrDatabaseMisconfiguration = errors.New("database misconfiguration")
)

// RelayerDatabase is a key-value store for relayer state, with each chainID maintaining its own state
Expand Down
18 changes: 13 additions & 5 deletions database/json_file_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package database

import (
"encoding/json"
"fmt"
"os"
"path/filepath"
"sync"
Expand Down Expand Up @@ -67,7 +68,10 @@ func NewJSONFileStorage(logger logging.Logger, dir string, networks []ids.ID) (*
func (s *JSONFileStorage) Get(chainID ids.ID, key []byte) ([]byte, error) {
mutex, ok := s.mutexes[chainID]
if !ok {
return nil, errors.New("database not configured for chain")
return nil, errors.Wrap(
ErrDatabaseMisconfiguration,
fmt.Sprintf("database not configured for chain %s", chainID.String()),
)
}

mutex.RLock()
Expand All @@ -86,18 +90,22 @@ func (s *JSONFileStorage) Get(chainID ids.ID, key []byte) ([]byte, error) {
return nil, ErrChainNotFound
}

if val, ok := currentState[string(key)]; ok {
return []byte(val), nil
var val string
if val, ok = currentState[string(key)]; !ok {
return nil, ErrKeyNotFound
}

return nil, ErrKeyNotFound
return []byte(val), nil
}

// Put the value into the json database. Read the current chain state and overwrite the key, if it exists
func (s *JSONFileStorage) Put(chainID ids.ID, key []byte, value []byte) error {
mutex, ok := s.mutexes[chainID]
if !ok {
return errors.Errorf("network does not exist. chainID: %s", chainID.String())
return errors.Wrap(
ErrDatabaseMisconfiguration,
fmt.Sprintf("database not configured for chain %s", chainID.String()),
)
}

mutex.Lock()
Expand Down
3 changes: 1 addition & 2 deletions vms/evm/subscriber.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,8 @@ func (s *subscriber) dialAndSubscribe() error {
return err
}

filterQuery := warpFilterQuery
evmLogs := make(chan types.Log, maxClientSubscriptionBuffer)
sub, err := ethClient.SubscribeFilterLogs(context.Background(), filterQuery, evmLogs)
sub, err := ethClient.SubscribeFilterLogs(context.Background(), warpFilterQuery, evmLogs)
if err != nil {
s.logger.Error(
"Failed to subscribe to logs",
Expand Down

0 comments on commit 532094c

Please sign in to comment.