diff --git a/database/database.go b/database/database.go index d432b469..152acb3d 100644 --- a/database/database.go +++ b/database/database.go @@ -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 diff --git a/database/json_file_storage.go b/database/json_file_storage.go index 73197208..a967224b 100644 --- a/database/json_file_storage.go +++ b/database/json_file_storage.go @@ -5,6 +5,7 @@ package database import ( "encoding/json" + "fmt" "os" "path/filepath" "sync" @@ -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() @@ -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() diff --git a/vms/evm/subscriber.go b/vms/evm/subscriber.go index e601d3fe..2f7bb505 100644 --- a/vms/evm/subscriber.go +++ b/vms/evm/subscriber.go @@ -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",