Skip to content

Commit

Permalink
fix: Cmd dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
red-0ne committed Oct 28, 2024
1 parent 2b14bab commit f050d8c
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 18 deletions.
18 changes: 17 additions & 1 deletion pkg/relayer/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,11 @@ func setupRelayerDependencies(
config.NewSupplyDelegationClientFn(), // leaf
config.NewSupplySharedQueryClientFn(), // leaf
config.NewSupplyServiceQueryClientFn(),
config.NewSupplyApplicationQuerierFn(),
supplyRelayMeter,
supplyMiner,
config.NewSupplyAccountQuerierFn(),
config.NewSupplyBankQuerierFn(),
config.NewSupplyApplicationQuerierFn(),
config.NewSupplySupplierQuerierFn(),
config.NewSupplySessionQuerierFn(),
config.NewSupplyProofQueryClientFn(),
Expand Down Expand Up @@ -228,6 +229,21 @@ func supplyMiner(
return depinject.Configs(deps, depinject.Supply(mnr)), nil
}

// supplyRelayMeter constructs a RelayMeter instance and returns a new
// depinject.Config which is supplied with the given deps and the new RelayMeter.
func supplyRelayMeter(
_ context.Context,
deps depinject.Config,
_ *cobra.Command,
) (depinject.Config, error) {
rm, err := proxy.NewRelayMeter(deps)
if err != nil {
return nil, err
}

return depinject.Configs(deps, depinject.Supply(rm)), nil
}

// supplyTxFactory constructs a cosmostx.Factory instance and returns a new
// depinject.Config which is supplied with the given deps and the new
// cosmostx.Factory.
Expand Down
18 changes: 1 addition & 17 deletions pkg/relayer/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,27 +118,11 @@ func NewRelayerProxy(
&rp.sessionQuerier,
&rp.sharedQuerier,
&rp.keyring,
&rp.relayMeter,
); err != nil {
return nil, err
}

rm := &ProxyRelayMeter{
apps: make(map[string]*appRelayMeter),
overServicingAllowance: 0,
}
if err := depinject.Inject(
deps,
&rm.sharedQuerier,
&rm.applicationQuerier,
&rm.serviceQuerier,
&rm.blockQuerier,
&rm.eventsQueryClient,
); err != nil {
return nil, err
}

rp.relayMeter = rm

servedRelays, servedRelaysProducer := channel.NewObservable[*types.Relay]()

rp.servedRelays = servedRelays
Expand Down
22 changes: 22 additions & 0 deletions pkg/relayer/proxy/relay_meter.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"strings"
"sync"

"cosmossdk.io/depinject"
"cosmossdk.io/math"
cosmostypes "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/gogoproto/proto"
Expand Down Expand Up @@ -43,6 +44,7 @@ type ProxyRelayMeter struct {
apps map[string]*appRelayMeter
// overServicingAllowance adjusts the max amount to allow for controlled over-servicing
// or, if negative, to create a stake buffer.
// TODO_TECHDEBT(@red-0ne): Expose overServicingAllowance as a configuration parameter.
overServicingAllowance int64

applicationQuerier client.ApplicationQueryClient
Expand All @@ -54,6 +56,26 @@ type ProxyRelayMeter struct {
relayMeterMu sync.Mutex
}

func NewRelayMeter(deps depinject.Config) (relayer.RelayMeter, error) {
rm := &ProxyRelayMeter{
apps: make(map[string]*appRelayMeter),
overServicingAllowance: 0,
}

if err := depinject.Inject(
deps,
&rm.sharedQuerier,
&rm.applicationQuerier,
&rm.serviceQuerier,
&rm.blockQuerier,
&rm.eventsQueryClient,
); err != nil {
return nil, err
}

return rm, nil
}

// Start starts the relay meter by observing application staked events and new sessions.
func (rmtr *ProxyRelayMeter) Start(ctx context.Context) error {
eventsObs, err := rmtr.eventsQueryClient.EventsBytes(ctx, "tm.event = 'Tx'")
Expand Down

0 comments on commit f050d8c

Please sign in to comment.