Skip to content

Commit

Permalink
Testnet Alpha version 7 (#159)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMarstonConnell authored Dec 7, 2022
2 parents da3800d + 21a56ee commit df0fff1
Show file tree
Hide file tree
Showing 10 changed files with 463 additions and 25 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,6 @@ dependency-graph.png
*.synctex.gz
contract_tests/*
app.test

mytestnet
_build
12 changes: 11 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ import (
*/

store "github.com/cosmos/cosmos-sdk/store/types"
alpha7 "github.com/jackalLabs/canine-chain/app/upgrades/alpha7"
v120alpha6 "github.com/jackalLabs/canine-chain/app/upgrades/v1.2.0-alpha.6"
v2 "github.com/jackalLabs/canine-chain/app/upgrades/v2"
v3 "github.com/jackalLabs/canine-chain/app/upgrades/v3"
Expand Down Expand Up @@ -1072,6 +1073,15 @@ func (app *JackalApp) setupUpgradeHandlers() {
),
)

// version 1.2.0-alpha.7 upgrade keeper
app.upgradeKeeper.SetUpgradeHandler(
alpha7.UpgradeName,
alpha7.CreateUpgradeHandler(
app.mm,
app.configurator,
),
)

// version 3 upgrade keeper
app.upgradeKeeper.SetUpgradeHandler(
v3.UpgradeName,
Expand Down Expand Up @@ -1103,7 +1113,7 @@ func (app *JackalApp) setupUpgradeHandlers() {

if upgradeInfo.Name == v3.UpgradeName {
storeUpgrades = &store.StoreUpgrades{
Added: []string{"storage"},
Added: []string{"storage", "filetree"},
}
}

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

const (
UpgradeName = "alpha7"
)
27 changes: 27 additions & 0 deletions app/upgrades/alpha7/upgrades.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package alpha7

import (
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/types"
)

func CreateUpgradeHandler(
mm *module.Manager,
configurator module.Configurator,
) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
logger := ctx.Logger().With("upgrade", UpgradeName)

if types.IsTestnet(ctx.ChainID()) {
logger.Debug("Updating to 1.2.0-alpha.7")
}

if types.IsMainnet(ctx.ChainID()) {
logger.Debug("Ignoring alpha7 for mainnet")
}

return mm.RunMigrations(ctx, configurator, vm)
}
}
2 changes: 2 additions & 0 deletions cmd/canined/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ func NewRootCmd() (*cobra.Command, params.EncodingConfig) {
}

initRootCmd(rootCmd, encodingConfig)
rootCmd.PersistentFlags().String(flags.FlagChainID, "", "The network chain ID")

return rootCmd, encodingConfig
}
Expand Down Expand Up @@ -174,6 +175,7 @@ func txCommand() *cobra.Command {
)

app.ModuleBasics.AddTxCommands(cmd)
cmd.PersistentFlags().String(flags.FlagChainID, "", "The network chain ID")
return cmd
}

Expand Down
70 changes: 70 additions & 0 deletions upgrades/v1.2.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Jackal v1.2.0 Upgrade Guide

## Installing New Binary

Clone the Jackal repo

```
git clone https://github.com/JackalLabs/canine-chain.git
cd canine-chain
```
Checkout the upgrade version

```
git fetch
git checkout v1.2.0
```

Build the binary

```
make build
```

The resulting binary will be `canine-chain/build/canined`

## Starting the Blockchain

### Cosmovisor Method

Ensure your chain is at the following block height: TODO

**If you halted your chain early, this may not be the case. I recommend following the Canined upgrade below any situation where your node is not already at the halt height.**

Copy the new binary in place of the existing genesis cosmovisor binary

```
cp $HOME/canine-chain/build/canined $HOME/.canine/cosmovisor/genesis/bin/canined
```

### Traditonal Method
Set the halt height in the canined app config
```
sed -i.bak 's/halt-height = 0/halt-height = TODO/' $HOME/.canine/config/app.toml
```

Wait until the planned upgrade time (approx. Dec 19 2022, 15:00 UTC)

At the uprgade time, run the binary to ensure the node syncs to the halt height

```
canined start
```

Once it stops due to the halt-height, replace the old canined binary with the new one:

```
cp $HOME/canine-chain/build/canined $(which canined)
```

Remove the halt-height from the config:

```
sed -i.bak 's/halt-height = TODO/halt-height = 0/' $HOME/.canine/config/app.toml
```

Restart the node:

```
canined start
```
77 changes: 68 additions & 9 deletions x/storage/keeper/msg_server_cancel_contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package keeper

import (
"context"
"crypto/sha256"
"encoding/json"
"fmt"
"io"

sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"

Expand All @@ -14,27 +16,86 @@ import (
func (k msgServer) CancelContract(goCtx context.Context, msg *types.MsgCancelContract) (*types.MsgCancelContractResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)

deal, found := k.GetActiveDeals(ctx, msg.Cid)
root := msg.Cid

h := sha256.New()
_, err := io.WriteString(h, fmt.Sprintf("%s%d", root, 0))
if err != nil {
return nil, err
}
hashName := h.Sum(nil)

left, err := MakeCid(hashName)
if err != nil {
return nil, err
}
h = sha256.New()
_, err = io.WriteString(h, fmt.Sprintf("%s%d", root, 1))
if err != nil {
return nil, err
}
hashName = h.Sum(nil)

right, err := MakeCid(hashName)
if err != nil {
return nil, err
}

var fid string

d, found := k.GetActiveDeals(ctx, root)
if !found {
return nil, fmt.Errorf("can't find contract")
s, found := k.GetStrays(ctx, root)
if !found {
return nil, fmt.Errorf("can't find contract")
}
k.RemoveStrays(ctx, s.Cid)
} else {
k.RemoveActiveDeals(ctx, d.Cid)
}

d, found = k.GetActiveDeals(ctx, left)
if !found {
s, found := k.GetStrays(ctx, left)
if !found {
return nil, fmt.Errorf("can't find contract")
}
k.RemoveStrays(ctx, s.Cid)
} else {
k.RemoveActiveDeals(ctx, d.Cid)
}

if deal.Creator != msg.Creator {
return nil, fmt.Errorf("you don't own this deal")
d, found = k.GetActiveDeals(ctx, right)
if !found {
s, found := k.GetStrays(ctx, right)
if !found {
return nil, fmt.Errorf("can't find contract")
}
fid = s.Fid
k.RemoveStrays(ctx, s.Cid)

} else {
fid = d.Fid
k.RemoveActiveDeals(ctx, d.Cid)
if d.Creator != msg.Creator {
return nil, fmt.Errorf("you don't own this deal")
}
}

ftc, found := k.GetFidCid(ctx, deal.Fid)
ftc, found := k.GetFidCid(ctx, fid)
if !found {
return nil, sdkerrors.Wrap(sdkerrors.ErrKeyNotFound, "no fid found")
}

var ncids []string
err := json.Unmarshal([]byte(ftc.Cids), &ncids)
err = json.Unmarshal([]byte(ftc.Cids), &ncids)
if err != nil {
return nil, err
}

cids := make([]string, 0)
for _, v := range ncids {
if v != msg.Cid {
if v != root && v != left && v != right {
cids = append(cids, v)
}
}
Expand All @@ -46,7 +107,5 @@ func (k msgServer) CancelContract(goCtx context.Context, msg *types.MsgCancelCon

k.SetFidCid(ctx, ftc)

k.RemoveActiveDeals(ctx, deal.Cid)

return &types.MsgCancelContractResponse{}, nil
}
2 changes: 1 addition & 1 deletion x/storage/keeper/msg_server_claim_stray.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (k msgServer) ClaimStray(goCtx context.Context, msg *types.MsgClaimStray) (
Signee: stray.Signee,
Provider: msg.Creator,
Startblock: fmt.Sprintf("%d", ctx.BlockHeight()),
Endblock: fmt.Sprintf("%d", ctx.BlockHeight()),
Endblock: "0",
Filesize: stray.Filesize,
Proofverified: "false",
Blocktoprove: fmt.Sprintf("%d", ctx.BlockHeight()/1024),
Expand Down
Loading

0 comments on commit df0fff1

Please sign in to comment.