diff --git a/proto/canine_chain/storage/params.proto b/proto/canine_chain/storage/params.proto index 9af0437d3..cf1bd3aa7 100644 --- a/proto/canine_chain/storage/params.proto +++ b/proto/canine_chain/storage/params.proto @@ -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; } diff --git a/x/storage/keeper/msg_server_buy_storage_test.go b/x/storage/keeper/msg_server_buy_storage_test.go index b73600114..d1d7fb0d6 100644 --- a/x/storage/keeper/msg_server_buy_storage_test.go +++ b/x/storage/keeper/msg_server_buy_storage_test.go @@ -24,6 +24,7 @@ func (suite *KeeperTestSuite) TestBuyStorage() { suite.storageKeeper.SetParams(suite.ctx, types.Params{ DepositAccount: depoAccount, ProofWindow: 50, + ChunkSize: 1024, }) cases := []struct { diff --git a/x/storage/keeper/msg_server_claim_stray.go b/x/storage/keeper/msg_server_claim_stray.go index ea9249091..0d3b74ccb 100644 --- a/x/storage/keeper/msg_server_claim_stray.go +++ b/x/storage/keeper/msg_server_claim_stray.go @@ -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 diff --git a/x/storage/keeper/msg_server_proofs_test.go b/x/storage/keeper/msg_server_proofs_test.go index ef2f71f41..8250c7c8f 100644 --- a/x/storage/keeper/msg_server_proofs_test.go +++ b/x/storage/keeper/msg_server_proofs_test.go @@ -139,6 +139,7 @@ func (suite *KeeperTestSuite) TestPostProof() { suite.storageKeeper.SetParams(suite.ctx, types.Params{ DepositAccount: depoAccount, ProofWindow: 50, + ChunkSize: 1024, }) // Init Provider diff --git a/x/storage/keeper/msg_server_sign_contract.go b/x/storage/keeper/msg_server_sign_contract.go index 9e1bdb38d..e311fa58b 100644 --- a/x/storage/keeper/msg_server_sign_contract.go +++ b/x/storage/keeper/msg_server_sign_contract.go @@ -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 diff --git a/x/storage/keeper/msg_server_upgrade_storage_test.go b/x/storage/keeper/msg_server_upgrade_storage_test.go index d66ae4f72..54661b673 100644 --- a/x/storage/keeper/msg_server_upgrade_storage_test.go +++ b/x/storage/keeper/msg_server_upgrade_storage_test.go @@ -24,6 +24,7 @@ func (suite *KeeperTestSuite) TestUpgradeStorage() { suite.storageKeeper.SetParams(suite.ctx, types.Params{ DepositAccount: testAccount, ProofWindow: 50, + ChunkSize: 1024, }) cases := []struct { diff --git a/x/storage/keeper/rewards.go b/x/storage/keeper/rewards.go index 392f68b6a..88cb315ab 100644 --- a/x/storage/keeper/rewards.go +++ b/x/storage/keeper/rewards.go @@ -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++ { @@ -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 diff --git a/x/storage/types/params.go b/x/storage/types/params.go index c9df5d8db..01d0ff259 100644 --- a/x/storage/types/params.go +++ b/x/storage/types/params.go @@ -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 @@ -26,6 +27,7 @@ func NewParams() Params { return Params{ DepositAccount: "jkl1778a6x4e6t074ajvs7l76wpa2xd0s4pt0tqq57", ProofWindow: 50, + ChunkSize: 1024, } } @@ -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), } } @@ -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 diff --git a/x/storage/types/params.pb.go b/x/storage/types/params.pb.go index 84c9726c3..19d57e0a8 100644 --- a/x/storage/types/params.pb.go +++ b/x/storage/types/params.pb.go @@ -27,6 +27,9 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package type Params struct { DepositAccount string `protobuf:"bytes,1,opt,name=deposit_account,json=depositAccount,proto3" json:"deposit_account,omitempty"` ProofWindow int64 `protobuf:"varint,2,opt,name=proof_window,json=proofWindow,proto3" json:"proof_window,omitempty"` + // Chunk size of a file is divided into + // The value cannot be smaller than 1 to avoid zero division + ChunkSize int64 `protobuf:"varint,3,opt,name=chunk_size,json=chunkSize,proto3" json:"chunk_size,omitempty"` } func (m *Params) Reset() { *m = Params{} } @@ -75,6 +78,13 @@ func (m *Params) GetProofWindow() int64 { return 0 } +func (m *Params) GetChunkSize() int64 { + if m != nil { + return m.ChunkSize + } + return 0 +} + func init() { proto.RegisterType((*Params)(nil), "canine_chain.storage.Params") } @@ -82,21 +92,23 @@ func init() { func init() { proto.RegisterFile("canine_chain/storage/params.proto", fileDescriptor_9a6380cb4192ac15) } var fileDescriptor_9a6380cb4192ac15 = []byte{ - // 223 bytes of a gzipped FileDescriptorProto + // 248 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x4c, 0x4e, 0xcc, 0xcb, 0xcc, 0x4b, 0x8d, 0x4f, 0xce, 0x48, 0xcc, 0xcc, 0xd3, 0x2f, 0x2e, 0xc9, 0x2f, 0x4a, 0x4c, 0x4f, 0xd5, 0x2f, 0x48, 0x2c, 0x4a, 0xcc, 0x2d, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, 0x41, 0x56, 0xa2, 0x07, 0x55, 0x22, 0x25, 0x92, 0x9e, 0x9f, 0x9e, 0x0f, 0x56, 0xa0, 0x0f, 0x62, 0x41, - 0xd4, 0x2a, 0x45, 0x71, 0xb1, 0x05, 0x80, 0xf5, 0x0a, 0xa9, 0x73, 0xf1, 0xa7, 0xa4, 0x16, 0xe4, + 0xd4, 0x2a, 0x55, 0x72, 0xb1, 0x05, 0x80, 0xf5, 0x0a, 0xa9, 0x73, 0xf1, 0xa7, 0xa4, 0x16, 0xe4, 0x17, 0x67, 0x96, 0xc4, 0x27, 0x26, 0x27, 0xe7, 0x97, 0xe6, 0x95, 0x48, 0x30, 0x2a, 0x30, 0x6a, 0x70, 0x06, 0xf1, 0x41, 0x85, 0x1d, 0x21, 0xa2, 0x42, 0x8a, 0x5c, 0x3c, 0x05, 0x45, 0xf9, 0xf9, 0x69, 0xf1, 0xe5, 0x99, 0x79, 0x29, 0xf9, 0xe5, 0x12, 0x4c, 0x0a, 0x8c, 0x1a, 0xcc, 0x41, 0xdc, - 0x60, 0xb1, 0x70, 0xb0, 0x90, 0x15, 0xcb, 0x8c, 0x05, 0xf2, 0x0c, 0x4e, 0x3e, 0x27, 0x1e, 0xc9, - 0x31, 0x5e, 0x78, 0x24, 0xc7, 0xf8, 0xe0, 0x91, 0x1c, 0xe3, 0x84, 0xc7, 0x72, 0x0c, 0x17, 0x1e, - 0xcb, 0x31, 0xdc, 0x78, 0x2c, 0xc7, 0x10, 0x65, 0x94, 0x9e, 0x59, 0x92, 0x51, 0x9a, 0xa4, 0x97, - 0x9c, 0x9f, 0xab, 0x9f, 0x95, 0x98, 0x9c, 0x9d, 0x98, 0xe3, 0x93, 0x98, 0x54, 0xac, 0x0f, 0x71, - 0xb7, 0x2e, 0xc4, 0x6b, 0x15, 0x70, 0xcf, 0x95, 0x54, 0x16, 0xa4, 0x16, 0x27, 0xb1, 0x81, 0x1d, - 0x6c, 0x0c, 0x08, 0x00, 0x00, 0xff, 0xff, 0xe7, 0x49, 0x3d, 0x9c, 0x01, 0x01, 0x00, 0x00, + 0x60, 0xb1, 0x70, 0xb0, 0x90, 0x90, 0x2c, 0x17, 0x57, 0x72, 0x46, 0x69, 0x5e, 0x76, 0x7c, 0x71, + 0x66, 0x55, 0xaa, 0x04, 0x33, 0x58, 0x01, 0x27, 0x58, 0x24, 0x38, 0xb3, 0x2a, 0xd5, 0x8a, 0x65, + 0xc6, 0x02, 0x79, 0x06, 0x27, 0x9f, 0x13, 0x8f, 0xe4, 0x18, 0x2f, 0x3c, 0x92, 0x63, 0x7c, 0xf0, + 0x48, 0x8e, 0x71, 0xc2, 0x63, 0x39, 0x86, 0x0b, 0x8f, 0xe5, 0x18, 0x6e, 0x3c, 0x96, 0x63, 0x88, + 0x32, 0x4a, 0xcf, 0x2c, 0xc9, 0x28, 0x4d, 0xd2, 0x4b, 0xce, 0xcf, 0xd5, 0xcf, 0x4a, 0x4c, 0xce, + 0x4e, 0xcc, 0xf1, 0x49, 0x4c, 0x2a, 0xd6, 0x87, 0x78, 0x4b, 0x17, 0xe2, 0xf3, 0x0a, 0xb8, 0xdf, + 0x4b, 0x2a, 0x0b, 0x52, 0x8b, 0x93, 0xd8, 0xc0, 0xfe, 0x31, 0x06, 0x04, 0x00, 0x00, 0xff, 0xff, + 0x92, 0xaa, 0x3a, 0xe9, 0x20, 0x01, 0x00, 0x00, } func (m *Params) Marshal() (dAtA []byte, err error) { @@ -119,6 +131,11 @@ func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if m.ChunkSize != 0 { + i = encodeVarintParams(dAtA, i, uint64(m.ChunkSize)) + i-- + dAtA[i] = 0x18 + } if m.ProofWindow != 0 { i = encodeVarintParams(dAtA, i, uint64(m.ProofWindow)) i-- @@ -158,6 +175,9 @@ func (m *Params) Size() (n int) { if m.ProofWindow != 0 { n += 1 + sovParams(uint64(m.ProofWindow)) } + if m.ChunkSize != 0 { + n += 1 + sovParams(uint64(m.ChunkSize)) + } return n } @@ -247,6 +267,25 @@ func (m *Params) Unmarshal(dAtA []byte) error { break } } + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field ChunkSize", wireType) + } + m.ChunkSize = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.ChunkSize |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } default: iNdEx = preIndex skippy, err := skipParams(dAtA[iNdEx:])