diff --git a/app/app.go b/app/app.go index dcd15d75..5bdd1217 100644 --- a/app/app.go +++ b/app/app.go @@ -8,6 +8,8 @@ import ( "path/filepath" "strings" + v340 "github.com/jackalLabs/canine-chain/v3/app/upgrades/v340" + v330 "github.com/jackalLabs/canine-chain/v3/app/upgrades/v330" v320 "github.com/jackalLabs/canine-chain/v3/app/upgrades/v320" @@ -1156,6 +1158,7 @@ func (app *JackalApp) registerMainnetUpgradeHandlers() { app.registerUpgrade(v310.NewUpgrade(app.mm, app.configurator)) app.registerUpgrade(v320.NewUpgrade(app.mm, app.configurator, app.StorageKeeper)) app.registerUpgrade(v330.NewUpgrade(app.mm, app.configurator)) + app.registerUpgrade(v340.NewUpgrade(app.mm, app.configurator)) } // registerUpgrade registers the given upgrade to be supported by the app diff --git a/app/upgrades/v340/upgrades.go b/app/upgrades/v340/upgrades.go new file mode 100644 index 00000000..cdfbca5e --- /dev/null +++ b/app/upgrades/v340/upgrades.go @@ -0,0 +1,42 @@ +package v340 + +import ( + storetypes "github.com/cosmos/cosmos-sdk/store/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" + "github.com/jackalLabs/canine-chain/v3/app/upgrades" +) + +var _ upgrades.Upgrade = &Upgrade{} + +// Upgrade represents the v3 upgrade +type Upgrade struct { + mm *module.Manager + configurator module.Configurator +} + +// NewUpgrade returns a new Upgrade instance +func NewUpgrade(mm *module.Manager, configurator module.Configurator) *Upgrade { + return &Upgrade{ + mm: mm, + configurator: configurator, + } +} + +// Name implements upgrades.Upgrade +func (u *Upgrade) Name() string { + return "v340" +} + +// Handler implements upgrades.Upgrade +func (u *Upgrade) Handler() upgradetypes.UpgradeHandler { + return func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { + return fromVM, nil + } +} + +// StoreUpgrades implements upgrades.Upgrade +func (u *Upgrade) StoreUpgrades() *storetypes.StoreUpgrades { + return &storetypes.StoreUpgrades{} +} diff --git a/x/storage/abci.go b/x/storage/abci.go index d6cdf85f..9e06d565 100644 --- a/x/storage/abci.go +++ b/x/storage/abci.go @@ -12,10 +12,10 @@ import ( func BeginBlocker(ctx sdk.Context, k keeper.Keeper) { defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyBeginBlocker) - err := k.HandleRewardBlock(ctx) - if err != nil { - ctx.Logger().Error(err.Error()) - } + // err := k.HandleRewardBlock(ctx) + // if err != nil { + // ctx.Logger().Error(err.Error()) + // } k.KillOldContracts(ctx) diff --git a/x/storage/keeper/msg_server_sign_contract.go b/x/storage/keeper/msg_server_sign_contract.go index 50324965..7eb72fb6 100644 --- a/x/storage/keeper/msg_server_sign_contract.go +++ b/x/storage/keeper/msg_server_sign_contract.go @@ -2,177 +2,11 @@ package keeper import ( "context" - "crypto/sha256" - "encoding/json" "fmt" - "io" - sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/jackalLabs/canine-chain/v3/x/storage/types" ) -func (k msgServer) SignContract(goCtx context.Context, msg *types.MsgSignContract) (*types.MsgSignContractResponse, error) { - ctx := sdk.UnwrapSDKContext(goCtx) - - contract, found := k.GetContracts(ctx, msg.Cid) - if !found { - return nil, fmt.Errorf("contract not found") - } - - _, found = k.GetActiveDeals(ctx, msg.Cid) - if found { - return nil, fmt.Errorf("contract already exists") - } - - _, found = k.GetStrays(ctx, msg.Cid) - if found { - return nil, fmt.Errorf("contract already exists") - } - - if contract.Signee != msg.Creator { - 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(k.GetParams(ctx).ChunkSize)) - - var pieceToStart int64 - - if !pieces.IsZero() { - pieceToStart = ctx.BlockHeight() % pieces.Int64() - } - - var end int64 - if msg.PayOnce { - - s := size.Quo(sdk.NewInt(1_000_000)).Int64() // round to mbs - if s <= 0 { - s = 1 - } - cost := k.GetStorageCostKbs(ctx, s*1000, 720*12*200) // pay for 200 years in mbs - - deposit, err := sdk.AccAddressFromBech32(k.GetParams(ctx).DepositAccount) - if err != nil { - return nil, err - } - - senderAddress, err := sdk.AccAddressFromBech32(msg.Creator) - if err != nil { - return nil, err - } - costCoins := sdk.NewCoins(sdk.NewCoin("ujkl", cost)) - err = k.bankkeeper.SendCoinsFromAccountToModule(ctx, senderAddress, types.ModuleName, costCoins) - if err != nil { - return nil, err - } - err = k.bankkeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, deposit, costCoins) - if err != nil { - return nil, err - } - - end = (200*31_536_000)/6 + ctx.BlockHeight() - } - - deal := types.ActiveDeals{ - Cid: contract.Cid, - Signee: contract.Signee, - Provider: contract.Creator, - Startblock: fmt.Sprintf("%d", ctx.BlockHeight()), - Endblock: fmt.Sprintf("%d", end), - Filesize: contract.Filesize, - LastProof: ctx.BlockHeight(), - Blocktoprove: fmt.Sprintf("%d", pieceToStart), - Creator: msg.Creator, - Proofsmissed: "0", - Merkle: contract.Merkle, - Fid: contract.Fid, - } - - if end == 0 { - fsize, ok := sdk.NewIntFromString(contract.Filesize) - if !ok { - return nil, fmt.Errorf("cannot parse file size") - } - payInfo, found := k.GetStoragePaymentInfo(ctx, msg.Creator) - if !found { - return nil, sdkerrors.Wrapf(sdkerrors.ErrNotFound, "payment info not found, please purchase storage space") - } - - // check if user has any free space - if (payInfo.SpaceUsed + (fsize.Int64() * 3)) > payInfo.SpaceAvailable { - return nil, fmt.Errorf("not enough storage space") - } - // check if storage subscription still active - if payInfo.End.Before(ctx.BlockTime()) { - return nil, fmt.Errorf("storage subscription has expired") - } - - payInfo.SpaceUsed += fsize.Int64() * 3 - - k.SetStoragePaymentInfo(ctx, payInfo) - } - - k.SetActiveDeals(ctx, deal) - k.RemoveContracts(ctx, contract.Cid) - - ftc, found := k.GetFidCid(ctx, contract.Fid) - - cids := []string{contract.Cid} - - if found { - var ncids []string - err := json.Unmarshal([]byte(ftc.Cids), &ncids) - if err != nil { - return nil, err - } - - cids = append(cids, ncids...) - } - - for i := 0; i < 2; i++ { - h := sha256.New() - _, err := io.WriteString(h, fmt.Sprintf("%s%d", contract.Cid, i)) - if err != nil { - return nil, err - } - hashName := h.Sum(nil) - - scid, err := MakeCid(hashName) - if err != nil { - return nil, err - } - - newContract := types.Strays{ - Cid: scid, - Signee: contract.Signee, - Fid: contract.Fid, - Filesize: contract.Filesize, - Merkle: contract.Merkle, - End: end, - } - - cids = append(cids, scid) - - k.SetStrays(ctx, newContract) - - } - - cidarr, err := json.Marshal(cids) - if err != nil { - return nil, err - } - - nftc := types.FidCid{ - Fid: contract.Fid, - Cids: string(cidarr), - } - - k.SetFidCid(ctx, nftc) - - return &types.MsgSignContractResponse{}, nil +func (k msgServer) SignContract(_ context.Context, _ *types.MsgSignContract) (*types.MsgSignContractResponse, error) { + return nil, fmt.Errorf("disabled new files until v4") }