Skip to content

Commit

Permalink
1.2.0 fixes for mainnet (#150)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMarstonConnell authored Dec 4, 2022
2 parents 11cc90c + d50bae4 commit fc016e4
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 54 deletions.
2 changes: 1 addition & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ func NewJackalApp(
app.AccountKeeper,
app.BankKeeper,
authtypes.FeeCollectorName,
// storagemoduletypes.ModuleName,
storagemoduletypes.ModuleName,
)
mintModule := mint.NewAppModule(appCodec, app.MintKeeper, app.AccountKeeper, app.BankKeeper)

Expand Down
4 changes: 2 additions & 2 deletions proto/canine_chain/jklmint/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ option go_package = "github.com/jackalLabs/canine-chain/x/jklmint/types";
service Query {
// Parameters queries the parameters of the module.
rpc Params(QueryParamsRequest) returns (QueryParamsResponse) {
option (google.api.http).get = "/jackal-dao/canine-chain/jklmint/params";
option (google.api.http).get = "/cosmos/mint/v1beta1/params";
}

// Inflation returns the current minting inflation value.
rpc Inflation(QueryInflationRequest) returns (QueryInflationResponse) {
option (google.api.http).get = "/jackal-dao/canine-chain/jklmint/inflation";
option (google.api.http).get = "/cosmos/mint/v1beta1/inflation";
}
}

Expand Down
8 changes: 4 additions & 4 deletions x/jklmint/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type (
stakingKeeper types.StakingKeeper
bankKeeper types.BankKeeper
feeCollectorName string
// miningName string
miningName string
}
)

Expand All @@ -33,7 +33,7 @@ func NewKeeper(
ak types.AccountKeeper,
bk types.BankKeeper,
feeCollectorName string,
// miningName string,
miningName string,
) Keeper {
// ensure mint module account is set
if addr := ak.GetModuleAddress(types.ModuleName); addr == nil {
Expand All @@ -52,7 +52,7 @@ func NewKeeper(
stakingKeeper: sk,
bankKeeper: bk,
feeCollectorName: feeCollectorName,
// miningName: miningName,
miningName: miningName,
}
}

Expand Down Expand Up @@ -96,7 +96,7 @@ func (k Keeper) GetInflation(ctx sdk.Context) (sdk.Dec, error) {

var blocksPerYearEstiamte int64 = (365 * 24 * 60 * 60) / 6

printedPerYear := blocksPerYearEstiamte * 4_000_000
printedPerYear := blocksPerYearEstiamte * 10_000_000

inflate := sdk.NewDec(printedPerYear)

Expand Down
25 changes: 13 additions & 12 deletions x/jklmint/keeper/mint.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,42 @@ import (
"github.com/cosmos/cosmos-sdk/telemetry"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/jackalLabs/canine-chain/x/jklmint/types"
storeTypes "github.com/jackalLabs/canine-chain/x/storage/types"
)

func (k Keeper) BlockMint(ctx sdk.Context) {
var validatorRatio int64 = 4
// var providerRatio int64 = 6
var providerRatio int64 = 6

denom := k.GetParams(ctx).MintDenom

totalCoin := sdk.NewCoin(denom, sdk.NewInt((validatorRatio)*1000000))
totalCoin := sdk.NewCoin(denom, sdk.NewInt((validatorRatio+providerRatio)*1000000))

// mint coins, update supply
mintedCoin := sdk.NewCoin(denom, sdk.NewInt(validatorRatio*1000000))
mintedCoins := sdk.NewCoins(mintedCoin)

// mint coins, update supply
providerCoin := sdk.NewCoin(denom, sdk.NewInt(providerRatio*1000000))
providerCoins := sdk.NewCoins(providerCoin)

err := k.MintCoins(ctx, sdk.NewCoins(totalCoin))
if err != nil {
panic(err)
}

err = k.bankKeeper.SendCoinsFromModuleToModule(ctx, types.ModuleName, storeTypes.ModuleName, providerCoins)
if err != nil {
panic(err)
}

// send the minted coins to the fee collector account
err = k.AddCollectedFees(ctx, mintedCoins)
if err != nil {
panic(err)
}

// mint coins, update supply
// providerCoin := sdk.NewCoin(denom, sdk.NewInt(providerRatio*1000000))
// providerCoins := sdk.NewCoins(providerCoin)

// err = k.SendToProviders(ctx, providerCoins)
// if err != nil {
// panic(err)
// }

if mintedCoin.Amount.IsInt64() {
if totalCoin.Amount.IsInt64() {
defer telemetry.ModuleSetGauge(types.ModuleName, float32(totalCoin.Amount.Int64()), "minted_tokens")
}

Expand Down
5 changes: 3 additions & 2 deletions x/jklmint/keeper/mint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ func (suite *MintTestSuite) TestBlockMint() {
Address: feeAccount.GetAddress().String(),
Denom: denom,
})

suite.Require().NoError(err)
suite.Require().Equal(sdk.NewInt(4000000), feeBalanceAfter.Balance.Amount)
supplyAfter, err := app.BankKeeper.TotalSupply(sdk.WrapSDKContext(ctx), &types.QueryTotalSupplyRequest{})
suite.Require().NoError(err)
suite.Require().Equal(1, len(supplyAfter.Supply))
suite.Require().Equal(sdk.NewInt(4000000), supplyAfter.Supply.AmountOf(denom))
// After BlockMint we now have exactly 4JKL in the fee collector account
suite.Require().Equal(sdk.NewInt(10000000), supplyAfter.Supply.AmountOf(denom))
// After BlockMint we now have exactly 10JKL in the fee collector account
}
5 changes: 5 additions & 0 deletions x/jklmint/module.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package jklmint

import (
"context"
"encoding/json"
"fmt"

Expand Down Expand Up @@ -76,6 +77,10 @@ func (AppModuleBasic) RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Rout

// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the module.
func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) {
err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx))
if err != nil {
fmt.Println(err)
}
}

// GetTxCmd returns the capability module's root tx command.
Expand Down
51 changes: 26 additions & 25 deletions x/jklmint/types/query.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions x/jklmint/types/query.pb.gw.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 14 additions & 6 deletions x/storage/keeper/msg_server_sign_contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,19 @@ func (k msgServer) SignContract(goCtx context.Context, msg *types.MsgSignContrac
return nil, fmt.Errorf("you do not have permission to approve this contract")
}

size, ok := sdk.NewIntFromString(contract.Filesize)
if !ok {
return nil, fmt.Errorf("cannot parse size")
}

pieces := size.Quo(sdk.NewInt(1024))

var pieceToStart int64

if !pieces.IsZero() {
pieceToStart = ctx.BlockHeight() % pieces.Int64()
}

deal := types.ActiveDeals{
Cid: contract.Cid,
Signee: contract.Signee,
Expand All @@ -31,7 +44,7 @@ func (k msgServer) SignContract(goCtx context.Context, msg *types.MsgSignContrac
Endblock: fmt.Sprintf("%d", ctx.BlockHeight()),
Filesize: contract.Filesize,
Proofverified: "false",
Blocktoprove: fmt.Sprintf("%d", ctx.BlockHeight()/1024),
Blocktoprove: fmt.Sprintf("%d", pieceToStart),
Creator: msg.Creator,
Proofsmissed: "0",
Merkle: contract.Merkle,
Expand All @@ -46,11 +59,6 @@ func (k msgServer) SignContract(goCtx context.Context, msg *types.MsgSignContrac
}
}

size, ok := sdk.NewIntFromString(contract.Filesize)
if !ok {
return nil, fmt.Errorf("cannot parse filesize")
}

used, ok := sdk.NewIntFromString(usage.Usage)
if !ok {
return nil, fmt.Errorf("cannot parse usage")
Expand Down

0 comments on commit fc016e4

Please sign in to comment.