diff --git a/x/tally/keeper/endblock.go b/x/tally/keeper/endblock.go index cea05aec..19140501 100644 --- a/x/tally/keeper/endblock.go +++ b/x/tally/keeper/endblock.go @@ -248,7 +248,12 @@ func (k Keeper) FilterAndTally(ctx sdk.Context, req types.Request) (TallyResult, if err != nil { return result, k.logErrAndRet(ctx, err, types.ErrGettingMaxTallyGasLimit, req) } - gasLimit := min(req.TallyGasLimit, maxGasLimit) - filterResult.GasUsed + var gasLimit uint64 + if min(req.TallyGasLimit, maxGasLimit) > filterResult.GasUsed { + gasLimit = min(req.TallyGasLimit, maxGasLimit) - filterResult.GasUsed + } else { + gasLimit = 0 + } k.Logger(ctx).Info( "executing tally VM", diff --git a/x/tally/keeper/filter.go b/x/tally/keeper/filter.go index 05faaff0..faee9165 100644 --- a/x/tally/keeper/filter.go +++ b/x/tally/keeper/filter.go @@ -5,6 +5,7 @@ import ( "fmt" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/sedaprotocol/seda-chain/x/tally/types" ) @@ -27,7 +28,7 @@ type FilterResult struct { // index i is an outlier, consensus boolean, consensus data proxy // public keys, and error. It assumes that the reveals and their // proxy public keys are sorted. -func (k Keeper) ApplyFilter(ctx sdk.Context, input []byte, reveals []types.RevealBody, replicationFactor int64) (FilterResult, error) { +func (k Keeper) ApplyFilter(ctx sdk.Context, input []byte, reveals []types.RevealBody, replicationFactor uint16) (FilterResult, error) { var result FilterResult result.Outliers = make([]int, len(reveals)) diff --git a/x/tally/keeper/filter_fuzz_test.go b/x/tally/keeper/filter_fuzz_test.go index 129a154d..7bdcc193 100644 --- a/x/tally/keeper/filter_fuzz_test.go +++ b/x/tally/keeper/filter_fuzz_test.go @@ -61,7 +61,7 @@ func FuzzStdDevFilter(f *testing.F) { filter, err := hex.DecodeString(filterHex) require.NoError(t, err) - result, err := fixture.tallyKeeper.ApplyFilter(fixture.Context(), filter, reveals, int64(len(reveals))) + result, err := fixture.tallyKeeper.ApplyFilter(fixture.Context(), filter, reveals, uint16(len(reveals))) require.Equal(t, expOutliers, result.Outliers) require.ErrorIs(t, err, nil) }) diff --git a/x/tally/keeper/filter_test.go b/x/tally/keeper/filter_test.go index 3da72f1a..79925ccb 100644 --- a/x/tally/keeper/filter_test.go +++ b/x/tally/keeper/filter_test.go @@ -643,7 +643,7 @@ func TestFilter(t *testing.T) { sort.Strings(tt.reveals[i].ProxyPubKeys) } - result, err := f.tallyKeeper.ApplyFilter(f.Context(), filter, tt.reveals, int64(len(tt.reveals))) + result, err := f.tallyKeeper.ApplyFilter(f.Context(), filter, tt.reveals, uint16(len(tt.reveals))) require.ErrorIs(t, err, tt.wantErr) if tt.consPubKeys == nil { require.Nil(t, nil, result.ProxyPubKeys) diff --git a/x/tally/types/abci_types.go b/x/tally/types/abci_types.go index f8b6b55c..1db768e5 100644 --- a/x/tally/types/abci_types.go +++ b/x/tally/types/abci_types.go @@ -21,7 +21,7 @@ type Request struct { GasPrice string `json:"gas_price"` Memo string `json:"memo"` PaybackAddress string `json:"payback_address"` - ReplicationFactor int64 `json:"replication_factor"` + ReplicationFactor uint16 `json:"replication_factor"` ConsensusFilter string `json:"consensus_filter"` Commits map[string][]byte `json:"commits"` Reveals map[string]RevealBody `json:"reveals"`