-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* grpc test setup * add umee client * UmeeClient updates WIP * update e2e genesis * add testing price_store * price store update * set chain id * price feeder gas fix * update e2e test price feeder config * fix IBC tests * check all accepted denom medians * remove extra prints * add error * linter fixes Co-authored-by: zarazan <zarazan@users.noreply.github.com>
- Loading branch information
1 parent
ec76a9d
commit 1737cb4
Showing
11 changed files
with
707 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,3 +37,6 @@ dist/ | |
|
||
# OSX | ||
*.DS_Store | ||
|
||
# e2e test keychain folder | ||
tests/e2e/keyring-test |
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,112 @@ | ||
package grpc | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"sync" | ||
|
||
"github.com/rs/zerolog" | ||
tmrpcclient "github.com/tendermint/tendermint/rpc/client" | ||
tmctypes "github.com/tendermint/tendermint/rpc/core/types" | ||
tmtypes "github.com/tendermint/tendermint/types" | ||
) | ||
|
||
var ( | ||
errParseEventDataNewBlockHeader = errors.New("error parsing EventDataNewBlockHeader") | ||
queryEventNewBlockHeader = tmtypes.QueryForEvent(tmtypes.EventNewBlockHeader) | ||
) | ||
|
||
// ChainHeight is used to cache the chain height of the | ||
// current node which is being updated each time the | ||
// node sends an event of EventNewBlockHeader. | ||
// It starts a goroutine to subscribe to blockchain new block event and update the cached height. | ||
type ChainHeight struct { | ||
Logger zerolog.Logger | ||
|
||
mtx sync.RWMutex | ||
errGetChainHeight error | ||
lastChainHeight int64 | ||
HeightChanged chan (int64) | ||
} | ||
|
||
// NewChainHeight returns a new ChainHeight struct that | ||
// starts a new goroutine subscribed to EventNewBlockHeader. | ||
func NewChainHeight( | ||
ctx context.Context, | ||
rpcClient tmrpcclient.Client, | ||
logger zerolog.Logger, | ||
) (*ChainHeight, error) { | ||
if !rpcClient.IsRunning() { | ||
if err := rpcClient.Start(); err != nil { | ||
return nil, err | ||
} | ||
} | ||
|
||
newBlockHeaderSubscription, err := rpcClient.Subscribe( | ||
ctx, tmtypes.EventNewBlockHeader, queryEventNewBlockHeader.String()) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
chainHeight := &ChainHeight{ | ||
Logger: logger.With().Str("oracle_client", "chain_height").Logger(), | ||
} | ||
chainHeight.HeightChanged = make(chan int64) | ||
|
||
go chainHeight.subscribe(ctx, rpcClient, newBlockHeaderSubscription) | ||
|
||
return chainHeight, nil | ||
} | ||
|
||
// updateChainHeight receives the data to be updated thread safe. | ||
func (chainHeight *ChainHeight) updateChainHeight(blockHeight int64, err error) { | ||
chainHeight.mtx.Lock() | ||
defer chainHeight.mtx.Unlock() | ||
|
||
if chainHeight.lastChainHeight != blockHeight { | ||
select { | ||
case chainHeight.HeightChanged <- blockHeight: | ||
default: | ||
} | ||
} | ||
chainHeight.lastChainHeight = blockHeight | ||
chainHeight.errGetChainHeight = err | ||
} | ||
|
||
// subscribe listens to new blocks being made | ||
// and updates the chain height. | ||
func (chainHeight *ChainHeight) subscribe( | ||
ctx context.Context, | ||
eventsClient tmrpcclient.EventsClient, | ||
newBlockHeaderSubscription <-chan tmctypes.ResultEvent, | ||
) { | ||
for { | ||
select { | ||
case <-ctx.Done(): | ||
err := eventsClient.Unsubscribe(ctx, tmtypes.EventNewBlockHeader, queryEventNewBlockHeader.String()) | ||
if err != nil { | ||
chainHeight.Logger.Err(err) | ||
chainHeight.updateChainHeight(chainHeight.lastChainHeight, err) | ||
} | ||
chainHeight.Logger.Info().Msg("closing the ChainHeight subscription") | ||
return | ||
|
||
case resultEvent := <-newBlockHeaderSubscription: | ||
eventDataNewBlockHeader, ok := resultEvent.Data.(tmtypes.EventDataNewBlockHeader) | ||
if !ok { | ||
chainHeight.Logger.Err(errParseEventDataNewBlockHeader) | ||
chainHeight.updateChainHeight(chainHeight.lastChainHeight, errParseEventDataNewBlockHeader) | ||
continue | ||
} | ||
chainHeight.updateChainHeight(eventDataNewBlockHeader.Header.Height, nil) | ||
} | ||
} | ||
} | ||
|
||
// GetChainHeight returns the last chain height available. | ||
func (chainHeight *ChainHeight) GetChainHeight() (int64, error) { | ||
chainHeight.mtx.RLock() | ||
defer chainHeight.mtx.RUnlock() | ||
|
||
return chainHeight.lastChainHeight, chainHeight.errGetChainHeight | ||
} |
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,34 @@ | ||
package grpc | ||
|
||
import ( | ||
"context" | ||
"net" | ||
"strings" | ||
) | ||
|
||
func dialerFunc(_ context.Context, addr string) (net.Conn, error) { | ||
return Connect(addr) | ||
} | ||
|
||
// Connect dials the given address and returns a net.Conn. The protoAddr | ||
// argument should be prefixed with the protocol, | ||
// eg. "tcp://127.0.0.1:8080" or "unix:///tmp/test.sock". | ||
func Connect(protoAddr string) (net.Conn, error) { | ||
proto, address := ProtocolAndAddress(protoAddr) | ||
conn, err := net.Dial(proto, address) | ||
return conn, err | ||
} | ||
|
||
// ProtocolAndAddress splits an address into the protocol and address components. | ||
// For instance, "tcp://127.0.0.1:8080" will be split into "tcp" and "127.0.0.1:8080". | ||
// If the address has no protocol prefix, the default is "tcp". | ||
func ProtocolAndAddress(listenAddr string) (string, string) { | ||
protocol, address := "tcp", listenAddr | ||
|
||
parts := strings.SplitN(address, "://", 2) | ||
if len(parts) == 2 { | ||
protocol, address = parts[0], parts[1] | ||
} | ||
|
||
return protocol, address | ||
} |
Oops, something went wrong.