Skip to content

Commit

Permalink
file deals are being correctly monitored and deleted when they fail
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMarstonConnell committed Oct 25, 2023
1 parent 2bca252 commit 8366aee
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 14 deletions.
2 changes: 1 addition & 1 deletion scripts/test-sequoia.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ canined collect-gentxs --home=$JKL_HOME

sed -i.bak -e "s/stake/ujkl/" $JKL_HOME/config/genesis.json
sed -i.bak -e "s/cosmos1arsaayyj5tash86mwqudmcs2fd5jt5zgp07gl8/jkl1arsaayyj5tash86mwqudmcs2fd5jt5zgc3sexc/" $JKL_HOME/config/genesis.json
sed -i.bak -e "s/\"proof_window\": \"50\"/\"proof_window\": \"100\"/" $JKL_HOME/config/genesis.json
sed -i.bak -e "s/\"proof_window\": \"50\"/\"proof_window\": \"40\"/" $JKL_HOME/config/genesis.json
sed -i.bak -e "s/\"chunk_size\": \"1024\"/\"chunk_size\": \"10240\"/" $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
Expand Down
2 changes: 1 addition & 1 deletion x/storage/client/cli/tx_post_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ func CmdPostFile() *cobra.Command {
address,
root,
int64(size),
100,
40,
0,
3,
"Uploaded with canined",
Expand Down
11 changes: 9 additions & 2 deletions x/storage/keeper/msg_server_postproof.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package keeper
import (
"context"
"fmt"

Check failure on line 5 in x/storage/keeper/msg_server_postproof.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofumpt`-ed (gofumpt)

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/jackalLabs/canine-chain/v3/x/storage/types"
)
Expand Down Expand Up @@ -31,7 +30,15 @@ func (k msgServer) PostProof(goCtx context.Context, msg *types.MsgPostProof) (*t
return &types.MsgPostProofResponse{Success: false, ErrorMessage: err.Error()}, nil
}
} else {
proof = file.AddProver(ctx, k, prover)
if file.ContainsProver(prover) {
var err error
proof, err = file.GetProver(ctx, k, prover)
if err != nil {
return &types.MsgPostProofResponse{Success: false, ErrorMessage: err.Error()}, nil
}
} else {
proof = file.AddProver(ctx, k, prover)
}
}

err := file.Prove(ctx, k, msg.Creator, msg.HashList, proof.ChunkToProve, msg.Item, proofSize)
Expand Down
14 changes: 9 additions & 5 deletions x/storage/keeper/rewards.go
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
package keeper

import (
"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/jackalLabs/canine-chain/v3/x/storage/types"
)

func (k Keeper) manageProofs(ctx sdk.Context, sizeTracker *map[string]int64, file *types.UnifiedFile, prover string) {
func (k Keeper) manageProofs(ctx sdk.Context, sizeTracker *map[string]int64, file *types.UnifiedFile, proofKey string) {
st := *sizeTracker

proof, found := k.GetProof(ctx, prover, file.Merkle, file.Owner, file.Start)
proof, found := k.GetProofWithBuiltKey(ctx, []byte(proofKey))
if !found {
file.RemoveProver(ctx, k, prover)
ctx.Logger().Info(fmt.Sprintf("cannot find proof: %s", proofKey))
file.RemoveProverWithKey(ctx, k, proofKey)
}

currentHeight := ctx.BlockHeight()

windowStart := currentHeight - file.ProofInterval

if windowStart > proof.LastProven { // if the last time this file was proven was outside the proof window, burn their stake in the file
file.RemoveProver(ctx, k, prover)
ctx.Logger().Info(fmt.Sprintf("proof has not been proven within the last window: %d > %d", windowStart, proof.LastProven))
file.RemoveProverWithKey(ctx, k, proofKey)
return
}

st[prover] += file.FileSize
st[proof.Prover] += file.FileSize
}

func (k Keeper) rewardProviders(totalSize int64, sizeTracker *map[string]int64) {
Expand Down
22 changes: 17 additions & 5 deletions x/storage/types/file_deal.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,25 +60,37 @@ func (f *UnifiedFile) AddProver(ctx sdk.Context, k ProofLoader, prover string) *
return &p
}

func (f *UnifiedFile) Save(ctx sdk.Context, k ProofLoader) {
k.SetFile(ctx, *f)
}

func (f *UnifiedFile) RemoveProver(ctx sdk.Context, k ProofLoader, prover string) {
pk := f.MakeProofKey(prover)
f.RemoveProverWithKey(ctx, k, pk)

Check failure on line 70 in x/storage/types/file_deal.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofumpt`-ed (gofumpt)
}

func (f *UnifiedFile) RemoveProverWithKey(ctx sdk.Context, k ProofLoader, proofKey string) {
if len(f.Proofs) == 0 {
return
}

pk := f.MakeProofKey(prover)

for i, proof := range f.Proofs {
if proof == pk {
ctx.Logger().Info(fmt.Sprintf("should we remove proof: %s == %s ?", proof, proofKey))
if proof == proofKey {
ctx.Logger().Info(fmt.Sprintf("removing proofs: %s == %s ?", proof, proofKey))

front := f.Proofs[:i]
back := f.Proofs[i+1:]

// nolint:all
f.Proofs = append(front, back...)

k.RemoveProofWithBuiltKey(ctx, []byte(pk))
return
k.RemoveProofWithBuiltKey(ctx, []byte(proofKey))
f.Save(ctx, k)
}
}

Check failure on line 93 in x/storage/types/file_deal.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofumpt`-ed (gofumpt)
}

func (f *UnifiedFile) GetProver(ctx sdk.Context, k ProofLoader, prover string) (*FileProof, error) {
Expand Down

0 comments on commit 8366aee

Please sign in to comment.