From 8366aee62a4ac7db579bed141def7c827c424a32 Mon Sep 17 00:00:00 2001 From: marston Date: Wed, 25 Oct 2023 16:48:08 -0400 Subject: [PATCH] file deals are being correctly monitored and deleted when they fail --- scripts/test-sequoia.sh | 2 +- x/storage/client/cli/tx_post_file.go | 2 +- x/storage/keeper/msg_server_postproof.go | 11 +++++++++-- x/storage/keeper/rewards.go | 14 +++++++++----- x/storage/types/file_deal.go | 22 +++++++++++++++++----- 5 files changed, 37 insertions(+), 14 deletions(-) diff --git a/scripts/test-sequoia.sh b/scripts/test-sequoia.sh index 078329c9a..c0bf7489d 100755 --- a/scripts/test-sequoia.sh +++ b/scripts/test-sequoia.sh @@ -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 diff --git a/x/storage/client/cli/tx_post_file.go b/x/storage/client/cli/tx_post_file.go index b983e29fa..c958e0275 100644 --- a/x/storage/client/cli/tx_post_file.go +++ b/x/storage/client/cli/tx_post_file.go @@ -222,7 +222,7 @@ func CmdPostFile() *cobra.Command { address, root, int64(size), - 100, + 40, 0, 3, "Uploaded with canined", diff --git a/x/storage/keeper/msg_server_postproof.go b/x/storage/keeper/msg_server_postproof.go index 12a7a1133..efd79926b 100644 --- a/x/storage/keeper/msg_server_postproof.go +++ b/x/storage/keeper/msg_server_postproof.go @@ -3,7 +3,6 @@ package keeper import ( "context" "fmt" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/jackalLabs/canine-chain/v3/x/storage/types" ) @@ -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) diff --git a/x/storage/keeper/rewards.go b/x/storage/keeper/rewards.go index 0f6b70281..c61143447 100644 --- a/x/storage/keeper/rewards.go +++ b/x/storage/keeper/rewards.go @@ -1,16 +1,19 @@ 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() @@ -18,11 +21,12 @@ func (k Keeper) manageProofs(ctx sdk.Context, sizeTracker *map[string]int64, fil 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) { diff --git a/x/storage/types/file_deal.go b/x/storage/types/file_deal.go index 095698c22..fe375ec8c 100644 --- a/x/storage/types/file_deal.go +++ b/x/storage/types/file_deal.go @@ -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) + +} + +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) } } + } func (f *UnifiedFile) GetProver(ctx sdk.Context, k ProofLoader, prover string) (*FileProof, error) {