Skip to content

Commit

Permalink
Fix: Piece to prove (#227)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMarstonConnell authored Jan 31, 2023
2 parents ec5e114 + 8705bca commit 6b50e4c
Show file tree
Hide file tree
Showing 17 changed files with 245 additions and 43 deletions.
6 changes: 4 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/jackalLabs/canine-chain/app/upgrades"
"github.com/jackalLabs/canine-chain/app/upgrades/testnet/alpha11"
"github.com/jackalLabs/canine-chain/app/upgrades/testnet/alpha13"
"github.com/jackalLabs/canine-chain/app/upgrades/testnet/fixstrays"
"github.com/jackalLabs/canine-chain/app/upgrades/testnet/killdeals"

"github.com/prometheus/client_golang/prometheus"
Expand Down Expand Up @@ -148,7 +149,7 @@ import (
notificationsmoduletypes "github.com/jackalLabs/canine-chain/x/notifications/types"
*/

v3 "github.com/jackalLabs/canine-chain/app/upgrades/v3"
"github.com/jackalLabs/canine-chain/app/upgrades/bouncybulldog"

// unnamed import of statik for swagger UI support
_ "github.com/cosmos/cosmos-sdk/client/docs/statik"
Expand Down Expand Up @@ -1123,10 +1124,11 @@ func (app *JackalApp) registerTestnetUpgradeHandlers() {
app.registerUpgrade(alpha11.NewUpgrade(app.mm, app.configurator, app.OracleKeeper))
app.registerUpgrade(alpha13.NewUpgrade(app.mm, app.configurator))
app.registerUpgrade(killdeals.NewUpgrade(app.mm, app.configurator, app.StorageKeeper))
app.registerUpgrade(fixstrays.NewUpgrade(app.mm, app.configurator, app.StorageKeeper))
}

func (app *JackalApp) registerMainnetUpgradeHandlers() {
app.registerUpgrade(v3.NewUpgrade(app.mm, app.configurator, app.OracleKeeper))
app.registerUpgrade(bouncybulldog.NewUpgrade(app.mm, app.configurator, app.OracleKeeper))
}

// registerUpgrade registers the given upgrade to be supported by the app
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package v3
package bouncybulldog

import (
storetypes "github.com/cosmos/cosmos-sdk/store/types"
"github.com/jackalLabs/canine-chain/app/upgrades"
"github.com/jackalLabs/canine-chain/types"
filetreemoduletypes "github.com/jackalLabs/canine-chain/x/filetree/types"
oraclekeeper "github.com/jackalLabs/canine-chain/x/oracle/keeper"
oraclemoduletypes "github.com/jackalLabs/canine-chain/x/oracle/types"
Expand Down Expand Up @@ -33,12 +34,17 @@ func NewUpgrade(mm *module.Manager, configurator module.Configurator, ok oraclek

// Name implements upgrades.Upgrade
func (u *Upgrade) Name() string {
return "v3"
return "bouncybulldog"
}

// Handler implements upgrades.Upgrade
func (u *Upgrade) Handler() upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
if types.IsTestnet(ctx.ChainID()) {
ctx.Logger().Error("Upgrade shouldn't run on testnet!")
return fromVM, nil
}

fromVM[storagemoduletypes.ModuleName] = 1
fromVM[filetreemoduletypes.ModuleName] = 1
fromVM[oraclemoduletypes.ModuleName] = 1
Expand Down
13 changes: 9 additions & 4 deletions app/upgrades/testnet/alpha11/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/cosmos/cosmos-sdk/types/module"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
"github.com/jackalLabs/canine-chain/app/upgrades"
"github.com/jackalLabs/canine-chain/types"
oraclekeeper "github.com/jackalLabs/canine-chain/x/oracle/keeper"
oraclemoduletypes "github.com/jackalLabs/canine-chain/x/oracle/types"
)
Expand Down Expand Up @@ -36,14 +37,18 @@ func (u *Upgrade) Name() string {
// Handler implements upgrades.Upgrade
func (u *Upgrade) Handler() upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
fromVM[oraclemoduletypes.ModuleName] = 1
if types.IsTestnet(ctx.ChainID()) {
fromVM[oraclemoduletypes.ModuleName] = 1

newVM, err := u.mm.RunMigrations(ctx, u.configurator, fromVM)
if err != nil {
newVM, err := u.mm.RunMigrations(ctx, u.configurator, fromVM)
if err != nil {
return newVM, err
}
return newVM, err

}

return newVM, err
return fromVM, nil
}
}

Expand Down
11 changes: 8 additions & 3 deletions app/upgrades/testnet/alpha13/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/cosmos/cosmos-sdk/types/module"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
"github.com/jackalLabs/canine-chain/app/upgrades"
"github.com/jackalLabs/canine-chain/types"
)

var _ upgrades.Upgrade = &Upgrade{}
Expand All @@ -32,12 +33,16 @@ func (u *Upgrade) Name() string {
// Handler implements upgrades.Upgrade
func (u *Upgrade) Handler() upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
newVM, err := u.mm.RunMigrations(ctx, u.configurator, fromVM)
if err != nil {
if types.IsTestnet(ctx.ChainID()) {
newVM, err := u.mm.RunMigrations(ctx, u.configurator, fromVM)
if err != nil {
return newVM, err
}

return newVM, err
}

return newVM, err
return fromVM, nil
}
}

Expand Down
75 changes: 75 additions & 0 deletions app/upgrades/testnet/fixstrays/upgrades.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package fixstrays

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/app/upgrades"
"github.com/jackalLabs/canine-chain/types"
storagemodulekeeper "github.com/jackalLabs/canine-chain/x/storage/keeper"
)

var _ upgrades.Upgrade = &Upgrade{}

// Upgrade represents the v4 upgrade
type Upgrade struct {
mm *module.Manager
configurator module.Configurator
storeageKeeper storagemodulekeeper.Keeper
}

// NewUpgrade returns a new Upgrade instance
func NewUpgrade(mm *module.Manager, configurator module.Configurator, storeageKeeper storagemodulekeeper.Keeper) *Upgrade {
return &Upgrade{
mm: mm,
configurator: configurator,
storeageKeeper: storeageKeeper,
}
}

// Name implements upgrades.Upgrade
func (u *Upgrade) Name() string {
return "fixstrays"
}

// Handler implements upgrades.Upgrade
func (u *Upgrade) Handler() upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
if types.IsTestnet(ctx.ChainID()) {

newVM, err := u.mm.RunMigrations(ctx, u.configurator, fromVM)
if err != nil {
return newVM, err
}

deals := u.storeageKeeper.GetAllActiveDeals(ctx)
for _, deal := range deals {
u.storeageKeeper.RemoveActiveDeals(ctx, deal.Cid)
}

strays := u.storeageKeeper.GetAllStrays(ctx)
for _, stray := range strays {
u.storeageKeeper.RemoveStrays(ctx, stray.Cid)
}

payinfo := u.storeageKeeper.GetAllStoragePaymentInfo(ctx)
for _, info := range payinfo {
u.storeageKeeper.RemoveStoragePaymentInfo(ctx, info.Address)
}

fidcid := u.storeageKeeper.GetAllFidCid(ctx)
for _, fc := range fidcid {
u.storeageKeeper.RemoveFidCid(ctx, fc.Fid)
}

return newVM, err
}
return fromVM, nil
}
}

// StoreUpgrades implements upgrades.Upgrade
func (u *Upgrade) StoreUpgrades() *storetypes.StoreUpgrades {
return &storetypes.StoreUpgrades{}
}
31 changes: 18 additions & 13 deletions app/upgrades/testnet/killdeals/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/cosmos/cosmos-sdk/types/module"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
"github.com/jackalLabs/canine-chain/app/upgrades"
"github.com/jackalLabs/canine-chain/types"
storagemodulekeeper "github.com/jackalLabs/canine-chain/x/storage/keeper"
)

Expand Down Expand Up @@ -35,22 +36,26 @@ func (u *Upgrade) Name() string {
// Handler implements upgrades.Upgrade
func (u *Upgrade) Handler() upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
newVM, err := u.mm.RunMigrations(ctx, u.configurator, fromVM)
if err != nil {
return newVM, err
}
if types.IsTestnet(ctx.ChainID()) {

deals := u.storeageKeeper.GetAllActiveDeals(ctx)
for _, deal := range deals {
u.storeageKeeper.RemoveActiveDeals(ctx, deal.Cid)
}
newVM, err := u.mm.RunMigrations(ctx, u.configurator, fromVM)
if err != nil {
return newVM, err
}

strays := u.storeageKeeper.GetAllStrays(ctx)
for _, stray := range strays {
u.storeageKeeper.RemoveStrays(ctx, stray.Cid)
}
deals := u.storeageKeeper.GetAllActiveDeals(ctx)
for _, deal := range deals {
u.storeageKeeper.RemoveActiveDeals(ctx, deal.Cid)
}

return newVM, err
strays := u.storeageKeeper.GetAllStrays(ctx)
for _, stray := range strays {
u.storeageKeeper.RemoveStrays(ctx, stray.Cid)
}

return newVM, err
}
return fromVM, nil
}
}

Expand Down
1 change: 1 addition & 0 deletions proto/canine_chain/storage/params.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ message Params {
option (gogoproto.goproto_stringer) = false;

string deposit_account = 1;
int64 proof_window = 2;
}
4 changes: 2 additions & 2 deletions scripts/test-provider.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,16 @@ canined gentx $ALIAS 200000000ujkl \
canined collect-gentxs --home=$JKL_HOME

sed -i.bak -e "s/stake/ujkl/" $JKL_HOME/config/genesis.json
sed -i.bak -e "s/\"proof_window\": \"50\"/\"proof_window\": \"3\"/" $JKL_HOME/config/genesis.json
sed -i.bak -e "s/^minimum-gas-prices *=.*/minimum-gas-prices = \"0.0025ujkl\"/" $JKL_HOME/config/app.toml
sed -i.bak -e 's/enable = false/enable=true/' $JKL_HOME/config/app.toml
sed -i.bak -e 's/enabled-unsafe-cors = false/enabled-unsafe-cors = true/' $JKL_HOME/config/app.toml
sed -i.bak -e 's/cors_allowed_origins = \[\]/cors_allowed_origins = \["*"\]/' $JKL_HOME/config/config.toml
sed -i.bak -e 's/chain-id = ""/chain-id = "canine-1"/' $JKL_HOME/config/client.toml

screen -d -m canined start --home=$JKL_HOME --log_level info
sleep 20
jprovd client config chain-id $CHAIN --home=$PROV_HOME
echo '{"key":"7d5a77d4e3dadb5103f45a884d1aad0310bc6eaabbc7c1426fd9909de27dc818","address":"jkl1p6tje2akcr8z5ghxqlpur06ep6uexf7fk2vy3y"}' > $PROV_HOME/config/priv_storkey.json
jprovd client balance --home=$PROV_HOME
jprovd init http://localhost:3333 1000000000 "" --home=$PROV_HOME
jprovd start --home=$PROV_HOME
jprovd start --home=$PROV_HOME --interval=5
2 changes: 1 addition & 1 deletion scripts/upgrade-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ UPGRADE_HEIGHT=20
HOME=mytestnet
ROOT=$(pwd)
DENOM=ujkl
SOFTWARE_UPGRADE_NAME=v3
SOFTWARE_UPGRADE_NAME=bouncybulldog

# underscore so that go tool will not take gocache into account
mkdir -p ${ROOT}/../_build/gocache
Expand Down
24 changes: 24 additions & 0 deletions upgrades/gov-props/v1.2.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# v1.2.0 - Bouncy Bulldog

## Summary
This upgrade allows the Jackal Network to start fulfilling its purpose as the Decentralized Storage Platform of the Cosmos. This upgrade introduces the Storage module, which allows users to pay for storage and create storage deals with Storage Providers. It also brings the addition of the Filetree module which creates a privacy layer and bucket file structure akin to S3 and Google Drive. Finally it also brings the addition of the Oracle module which allows other modules to query a data stream being supplied by a centralized entity. In this case, Jackal Labs will be using this oracle to supply pricing information while the AMM module is being finalized.
## Change Log
* Re-added Storage Module
* Re-added Filetree Module
* Added Oracle Module
* Fixed RNS marketplace bugs
* Increased Code Test Coverage to ~50%
* Fixed Go Package & Proto Layout
* Removed Ignite CLI as a dependency & fixed codegen bugs associated with it
* Improved Safety of Storage/Filetree modules from v1.1.1
* Updated Cosmwasm Version from v0.29.1 -> v0.29.2
* Updated CosmosSDK Version from v0.45.10 -> v0.45.11
* Updated IBC Version from v3.3.1 -> v3.4.0
* Updated Tendermint Version from Tendermint v0.34.22 -> [Informal's Tendermint](https://github.com/tendermint/tendermint/issues/9972) v0.34.23
* Updated Security of Storage Module proof mechanism from using Blake2b to Sha3-512
* Refactored HTTP server into new repo, see [canine-provider](https://github.com/JackalLabs/canine-provider)

For a full list of changes, please visit https://github.com/JackalLabs/canine-chain/compare/v1.1.2-hotfix...v23.01-beta

## Upgrading
See [the upgrade instructions](https://github.com/JackalLabs/canine-chain/blob/v23.01-beta/upgrades/v1.2.0.md) for full details on how to install and run this upgrade.
1 change: 1 addition & 0 deletions x/storage/keeper/msg_server_buy_storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func (suite *KeeperTestSuite) TestBuyStorage() {

suite.storageKeeper.SetParams(suite.ctx, types.Params{
DepositAccount: depoAccount,
ProofWindow: 50,
})

cases := []struct {
Expand Down
12 changes: 11 additions & 1 deletion x/storage/keeper/msg_server_claim_stray.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ func (k msgServer) ClaimStray(goCtx context.Context, msg *types.MsgClaimStray) (
}
}

size := sdk.NewInt(int64(stray.Size()))

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

var pieceToStart int64

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

deal := types.ActiveDeals{
Cid: stray.Cid,
Signee: stray.Signee,
Expand All @@ -38,7 +48,7 @@ func (k msgServer) ClaimStray(goCtx context.Context, msg *types.MsgClaimStray) (
Endblock: "0",
Filesize: stray.Filesize,
Proofverified: "false",
Blocktoprove: fmt.Sprintf("%d", ctx.BlockHeight()/1024),
Blocktoprove: fmt.Sprintf("%d", pieceToStart),
Creator: msg.Creator,
Proofsmissed: "0",
Merkle: stray.Merkle,
Expand Down
10 changes: 10 additions & 0 deletions x/storage/keeper/msg_server_sign_contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ func (k msgServer) SignContract(goCtx context.Context, msg *types.MsgSignContrac
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")
}
Expand Down
1 change: 1 addition & 0 deletions x/storage/keeper/msg_server_upgrade_storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func (suite *KeeperTestSuite) TestUpgradeStorage() {

suite.storageKeeper.SetParams(suite.ctx, types.Params{
DepositAccount: testAccount,
ProofWindow: 50,
})

cases := []struct {
Expand Down
Loading

0 comments on commit 6b50e4c

Please sign in to comment.