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

Jkl 249 replace block chunk size with param #248

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
3 changes: 3 additions & 0 deletions proto/canine_chain/storage/params.proto
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,7 @@ message Params {

string deposit_account = 1;
int64 proof_window = 2;
// Chunk size of a file is divided into
// The value cannot be smaller than 1 to avoid zero division
int64 chunk_size = 3;
}
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 @@ -24,6 +24,7 @@ func (suite *KeeperTestSuite) TestBuyStorage() {
suite.storageKeeper.SetParams(suite.ctx, types.Params{
DepositAccount: depoAccount,
ProofWindow: 50,
ChunkSize: 1024,
})

cases := []struct {
Expand Down
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 @@ -32,7 +32,7 @@ func (k msgServer) ClaimStray(goCtx context.Context, msg *types.MsgClaimStray) (

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

pieces := size.Quo(sdk.NewInt(1024))
pieces := size.Quo(sdk.NewInt(k.GetParams(ctx).ChunkSize))

var pieceToStart int64

Expand Down
1 change: 1 addition & 0 deletions x/storage/keeper/msg_server_proofs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ func (suite *KeeperTestSuite) TestPostProof() {
suite.storageKeeper.SetParams(suite.ctx, types.Params{
DepositAccount: depoAccount,
ProofWindow: 50,
ChunkSize: 1024,
})

// Init Provider
Expand Down
2 changes: 1 addition & 1 deletion x/storage/keeper/msg_server_sign_contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (k msgServer) SignContract(goCtx context.Context, msg *types.MsgSignContrac
return nil, fmt.Errorf("cannot parse size")
}

pieces := size.Quo(sdk.NewInt(1024))
pieces := size.Quo(sdk.NewInt(k.GetParams(ctx).ChunkSize))

var pieceToStart int64

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 @@ -24,6 +24,7 @@ func (suite *KeeperTestSuite) TestUpgradeStorage() {
suite.storageKeeper.SetParams(suite.ctx, types.Params{
DepositAccount: testAccount,
ProofWindow: 50,
ChunkSize: 1024,
})

cases := []struct {
Expand Down
6 changes: 1 addition & 5 deletions x/storage/keeper/rewards.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ import (
"github.com/jackalLabs/canine-chain/x/storage/types"
)

const (
fchunks int64 = 1024
)

func getTotalSize(allDeals []types.ActiveDeals) sdk.Dec {
networkSize := sdk.NewDecFromInt(sdk.NewInt(0))
for i := 0; i < len(allDeals); i++ {
Expand Down Expand Up @@ -48,7 +44,7 @@ func (k Keeper) manageDealReward(ctx sdk.Context, deal types.ActiveDeals, networ
byteHash = byte(ctx.BlockHeight()) // support for running simulations
}

d := totalSize.TruncateInt().Int64() / fchunks
d := totalSize.TruncateInt().Int64() / k.GetParams(ctx).ChunkSize

if d > 0 {
iprove = (int64(byteHash) + int64(ctx.BlockGasMeter().GasConsumed())) % d
Expand Down
16 changes: 16 additions & 0 deletions x/storage/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ var _ paramtypes.ParamSet = (*Params)(nil)
var (
KeyDepositAccount = []byte("DepositAccount")
KeyProofWindow = []byte("ProofWindow")
KeyChunkSize = []byte("ChunkSize")
)

// ParamKeyTable the param key table for launch module
Expand All @@ -26,6 +27,7 @@ func NewParams() Params {
return Params{
DepositAccount: "jkl1778a6x4e6t074ajvs7l76wpa2xd0s4pt0tqq57",
ProofWindow: 50,
ChunkSize: 1024,
}
}

Expand All @@ -39,6 +41,7 @@ func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs {
return paramtypes.ParamSetPairs{
paramtypes.NewParamSetPair(KeyDepositAccount, &p.DepositAccount, validateDeposit),
paramtypes.NewParamSetPair(KeyProofWindow, &p.ProofWindow, validateProofWindow),
paramtypes.NewParamSetPair(KeyChunkSize, &p.ChunkSize, validateChunkSize),
}
}

Expand Down Expand Up @@ -68,6 +71,19 @@ func validateDeposit(i interface{}) error {
return nil
}

func validateChunkSize(i interface{}) error {
v, ok := i.(int64)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}

if v < 1 {
return errors.New("chunk size cannot be smaller than 1")
}

return nil
}

// Validate validates the set of params
func (p Params) Validate() error {
return nil
Expand Down
55 changes: 47 additions & 8 deletions x/storage/types/params.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.