Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.2.0 fixes for mainnet. #157

Merged
merged 7 commits into from
Dec 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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