-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SessionManager] Skip claims creation if supplier operator balance is…
… too low (#817) ## Summary This PR introduces filters in the `SubmitClaims` step to ensure that the `SessionManager` only submits claims it can afford to prove. Before each submission, it checks the `SupplierOperator` balance and filters the claims based on the available funds. Claims are sorted by descending profitability to maximize rewards. ## Issue Since submitting a proof incurs a cost, a `SupplierOperator` without sufficient funds would be unable to submit the required proof. This could result in the supplier's stake being slashed if a proof submission is required. The `SessionManager` must verify that it can afford a proof submission before creating the corresponding claim. ## Type of change Select one or more from the following: - [x] New feature, functionality or library - [ ] Consensus breaking; add the `consensus-breaking` label if so. See #791 for details - [ ] Bug fix - [ ] Code health or cleanup - [ ] Documentation - [ ] Other (specify) ## Testing - [x] **Documentation**: `make docusaurus_start`; only needed if you make doc changes - [x] **Unit Tests**: `make go_develop_and_test` - [x] **LocalNet E2E Tests**: `make test_e2e` - [ ] **DevNet E2E Tests**: Add the `devnet-test-e2e` label to the PR. ## Sanity Checklist - [x] I have tested my changes using the available tooling - [x] I have commented my code - [x] I have performed a self-review of my own code; both comments & source code - [ ] I create and reference any new tickets, if applicable - [ ] I have left TODOs throughout the codebase, if applicable --------- Co-authored-by: Daniel Olshansky <[email protected]>
- Loading branch information
Showing
9 changed files
with
446 additions
and
84 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
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,57 @@ | ||
package query | ||
|
||
import ( | ||
"context" | ||
|
||
"cosmossdk.io/depinject" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" | ||
grpc "github.com/cosmos/gogoproto/grpc" | ||
|
||
"github.com/pokt-network/poktroll/app/volatile" | ||
"github.com/pokt-network/poktroll/pkg/client" | ||
) | ||
|
||
var _ client.BankQueryClient = (*bankQuerier)(nil) | ||
|
||
// bankQuerier is a wrapper around the banktypes.QueryClient that enables the | ||
// querying of on-chain balance information. | ||
type bankQuerier struct { | ||
clientConn grpc.ClientConn | ||
bankQuerier banktypes.QueryClient | ||
} | ||
|
||
// NewBankQuerier returns a new instance of a client.BankQueryClient by | ||
// injecting the dependecies provided by the depinject.Config. | ||
// | ||
// Required dependencies: | ||
// - clientCtx | ||
func NewBankQuerier(deps depinject.Config) (client.BankQueryClient, error) { | ||
bq := &bankQuerier{} | ||
|
||
if err := depinject.Inject( | ||
deps, | ||
&bq.clientConn, | ||
); err != nil { | ||
return nil, err | ||
} | ||
|
||
bq.bankQuerier = banktypes.NewQueryClient(bq.clientConn) | ||
|
||
return bq, nil | ||
} | ||
|
||
// GetBalance returns the uPOKT balance of a given address | ||
func (bq *bankQuerier) GetBalance( | ||
ctx context.Context, | ||
address string, | ||
) (*sdk.Coin, error) { | ||
// Query the blockchain for the balance record | ||
req := &banktypes.QueryBalanceRequest{Address: address, Denom: volatile.DenomuPOKT} | ||
res, err := bq.bankQuerier.Balance(ctx, req) | ||
if err != nil { | ||
return nil, ErrQueryBalanceNotFound.Wrapf("address: %s [%s]", address, err) | ||
} | ||
|
||
return res.Balance, nil | ||
} |
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
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
Oops, something went wrong.