Skip to content

Commit

Permalink
Keeper: add index by id
Browse files Browse the repository at this point in the history
  • Loading branch information
fynn-0xc committed Feb 27, 2023
1 parent 32ae2b0 commit 7c451df
Show file tree
Hide file tree
Showing 21 changed files with 1,279 additions and 970 deletions.
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ go 1.18

require (
cosmossdk.io/errors v1.0.0-beta.7
cosmossdk.io/math v1.0.0-beta.3
github.com/cosmos/cosmos-proto v1.0.0-beta.1
github.com/cosmos/cosmos-sdk v0.46.4
github.com/cosmos/ibc-go/v5 v5.0.0
Expand All @@ -29,6 +28,7 @@ require (
require golang.org/x/text v0.7.0 // indirect

require (
cosmossdk.io/math v1.0.0-beta.3
github.com/cosmos/go-bip39 v1.0.0
github.com/cosmos/gogoproto v1.4.6
github.com/prysmaticlabs/prysm v0.0.0-20220124113610-e26cde5e091b
Expand Down Expand Up @@ -228,8 +228,9 @@ require (
)

replace (
cosmossdk.io/math => github.com/bnb-chain/gnfd-cosmos-sdk/math v0.0.0-20230227041659-42c3a8e748d8
github.com/confio/ics23/go => github.com/cosmos/cosmos-sdk/ics23/go v0.8.0
github.com/cosmos/cosmos-sdk => github.com/bnb-chain/gnfd-cosmos-sdk v0.0.7
github.com/cosmos/cosmos-sdk => github.com/bnb-chain/gnfd-cosmos-sdk v0.0.2-0.20230227041659-42c3a8e748d8
github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1
github.com/tendermint/tendermint => github.com/bnb-chain/gnfd-tendermint v0.0.2
)
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ collectd.org v0.3.0/go.mod h1:A/8DzQBkF6abtvrT2j/AU/4tiBgJWYyh0y/oB/4MlWE=
contrib.go.opencensus.io/exporter/jaeger v0.2.1/go.mod h1:Y8IsLgdxqh1QxYxPC5IgXVmBaeLUeQFfBeBi9PbeZd0=
cosmossdk.io/errors v1.0.0-beta.7 h1:gypHW76pTQGVnHKo6QBkb4yFOJjC+sUGRc5Al3Odj1w=
cosmossdk.io/errors v1.0.0-beta.7/go.mod h1:mz6FQMJRku4bY7aqS/Gwfcmr/ue91roMEKAmDUDpBfE=
cosmossdk.io/math v1.0.0-beta.3 h1:TbZxSopz2LqjJ7aXYfn7nJSb8vNaBklW6BLpcei1qwM=
cosmossdk.io/math v1.0.0-beta.3/go.mod h1:3LYasri3Zna4XpbrTNdKsWmD5fHHkaNAod/mNT9XdE4=
dmitri.shuralyov.com/app/changes v0.0.0-20180602232624-0a106ad413e3/go.mod h1:Yl+fi1br7+Rr3LqpNJf1/uxUdtRUV+Tnj0o93V2B9MU=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
dmitri.shuralyov.com/html/belt v0.0.0-20180602232347-f7d459c86be0/go.mod h1:JLBrvjyP0v+ecvNYvCpyZgu5/xkfAUhi6wJj28eUfSU=
Expand Down Expand Up @@ -218,8 +216,10 @@ github.com/blang/semver v3.5.1+incompatible h1:cQNTCjp13qL8KC3Nbxr/y2Bqb63oX6wdn
github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk=
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4=
github.com/bmizerany/pat v0.0.0-20170815010413-6226ea591a40/go.mod h1:8rLXio+WjiTceGBHIoTvn60HIbs7Hm7bcHjyrSqYB9c=
github.com/bnb-chain/gnfd-cosmos-sdk v0.0.7 h1:HlTcn8YF9VSB1Dl/ys0mAehtm2tM9WEbF7M2zw/8y9I=
github.com/bnb-chain/gnfd-cosmos-sdk v0.0.7/go.mod h1:FrFE0FmMfUYySW5GdlV45b02SYUkNguECpVdZcUJVuU=
github.com/bnb-chain/gnfd-cosmos-sdk v0.0.2-0.20230227041659-42c3a8e748d8 h1:gB8SCOwfJtRcNQSM+5aJ6T5E9Y89Sk0YTI1TfnjI7+8=
github.com/bnb-chain/gnfd-cosmos-sdk v0.0.2-0.20230227041659-42c3a8e748d8/go.mod h1:FrFE0FmMfUYySW5GdlV45b02SYUkNguECpVdZcUJVuU=
github.com/bnb-chain/gnfd-cosmos-sdk/math v0.0.0-20230227041659-42c3a8e748d8 h1:3VgCDQl4sc8hfRb4V90ua/nu/fW9yk43enuc2wPPdw8=
github.com/bnb-chain/gnfd-cosmos-sdk/math v0.0.0-20230227041659-42c3a8e748d8/go.mod h1:u/MXvf8wbUbCsAEyQSSYXXMsczAsFX48e2D6JI86T4o=
github.com/bnb-chain/gnfd-tendermint v0.0.2 h1:2Oy7B5A7W/55teZNhlrFR9SamYNjCXAQNjwsbt534jM=
github.com/bnb-chain/gnfd-tendermint v0.0.2/go.mod h1:/v9z9F6cq0+f7EGG92lYSLBcPYQDILoK91X8YM28hWo=
github.com/boltdb/bolt v1.3.1/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps=
Expand Down
7 changes: 4 additions & 3 deletions proto/greenfield/storage/common.proto
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ enum SourceType {
enum ReadQuota {
option (gogoproto.goproto_enum_prefix) = false;

READ_QUOTA_FREE = 0;
READ_QUOTA_1G = 1;
READ_QUOTA_10G = 2;
READ_QUOTA_INVALID = 0;
READ_QUOTA_FREE = 1;
READ_QUOTA_1G = 2;
READ_QUOTA_10G = 3;
}

enum RedundancyType {
Expand Down
28 changes: 17 additions & 11 deletions proto/greenfield/storage/events.proto
Original file line number Diff line number Diff line change
Expand Up @@ -83,30 +83,36 @@ message EventCreateObject {
string bucket_name = 3;
// object_name define the name of object
string object_name = 4;
// id define an u256 id for object
string id = 6 [
// bucket_id define an u256 id for object
string bucket_id = 6 [
(cosmos_proto.scalar) = "cosmos.Uint",
(gogoproto.customtype) = "Uint",
(gogoproto.nullable) = false
];
// object_id define an u256 id for object
string object_id = 7 [
(cosmos_proto.scalar) = "cosmos.Uint",
(gogoproto.customtype) = "Uint",
(gogoproto.nullable) = false
];
// primary_sp_address define the account address of primary sp
string primary_sp_address = 7 [(cosmos_proto.scalar) = "cosmos.AddressString"];
string primary_sp_address = 8 [(cosmos_proto.scalar) = "cosmos.AddressString"];
// payload_size define the size of payload data which you want upload
uint64 payload_size = 8;
uint64 payload_size = 9;
// is_public define the highest permission of object.
bool is_public = 9;
bool is_public = 10;
// content_type define the content type of the payload data
string content_type = 10;
string content_type = 11;
// create_at define the block number when the object created
int64 create_at = 11;
int64 create_at = 12;
// status define the status of the object. INIT or IN_SERVICE or others
ObjectStatus status = 12;
ObjectStatus status = 13;
// redundancy_type define the type of redundancy. Replication or EC
RedundancyType redundancy_type = 13;
RedundancyType redundancy_type = 14;
// source_type define the source of the object. CrossChain or Greenfield origin
SourceType source_type = 14;
SourceType source_type = 15;
// checksums define the total checksums of the object which generated by redundancy
repeated bytes checksums = 15;
repeated bytes checksums = 16;
}

// EventSealObject is emitted on MsgSealObject
Expand Down
4 changes: 3 additions & 1 deletion proto/greenfield/storage/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,10 @@ message MsgCreateObject {
Approval primary_sp_approval = 7;
// expect_checksums is a list of hashes which was generate by redundancy algorithm.
repeated bytes expect_checksums = 8;
// redundancy_type can be ec or replica
RedundancyType redundancy_type = 9;
// expect_secondarySPs is a list of StorageProvider address, which is optional
repeated string expect_secondary_sp_addresses = 9 [(cosmos_proto.scalar) = "cosmos.AddressString"];
repeated string expect_secondary_sp_addresses = 10 [(cosmos_proto.scalar) = "cosmos.AddressString"];
}

message MsgCreateObjectResponse {}
Expand Down
6 changes: 3 additions & 3 deletions x/sp/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,17 @@ func (k msgServer) CreateStorageProvider(goCtx context.Context, msg *types.MsgCr

// check to see if the funding address has been registered before
if _, found := k.GetStorageProviderByFundingAddr(ctx, fundingAcc); found {
return nil, types.ErrStorageProviderOwnerExists
return nil, types.ErrStorageProviderFundingAddrExists
}

// check to see if the seal address has been registered before
if _, found := k.GetStorageProviderBySealAddr(ctx, sealAcc); found {
return nil, types.ErrStoraveProviderSealAddrExists
return nil, types.ErrStorageProviderSealAddrExists
}

// check to see if the approval address has been registered before
if _, found := k.GetStorageProviderByApprovalAddr(ctx, approvalAcc); found {
return nil, types.ErrStoraveProviderApprovalAddrExists
return nil, types.ErrStorageProviderApprovalAddrExists
}

if _, err := msg.Description.EnsureLength(); err != nil {
Expand Down
15 changes: 15 additions & 0 deletions x/sp/keeper/sp.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,21 @@ import (
"github.com/bnb-chain/greenfield/x/sp/types"
)

func (k Keeper) CheckIfValidStorageProvider(ctx sdk.Context, addr sdk.AccAddress) error {
store := ctx.KVStore(k.storeKey)

value := store.Get(types.GetStorageProviderKey(addr))
if value == nil {
return types.ErrStorageProviderNotFound
}

sp := types.MustUnmarshalStorageProvider(k.cdc, value)
if sp.Status != types.STATUS_IN_SERVICE {
return types.ErrStorageProviderNotInService
}
return nil
}

func (k Keeper) GetStorageProvider(ctx sdk.Context, addr sdk.AccAddress) (sp types.StorageProvider, found bool) {
store := ctx.KVStore(k.storeKey)

Expand Down
20 changes: 9 additions & 11 deletions x/sp/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,15 @@ import (

// x/sp module sentinel errors
var (
ErrEmptyStorageProviderAddr = errors.Register(ModuleName, 1, "empty StorageProvider address")
ErrStorageProviderNotFound = errors.Register(ModuleName, 2, "StorageProvider does not exist")
ErrEmptyStorageProviderPubKey = errors.Register(ModuleName, 3, "empty storage provider public key")
ErrStorageProviderOwnerExists = errors.Register(ModuleName, 4, "StorageProvider already exist for this operator address; must use new StorageProvider operator address")
ErrStorageProviderPubKeyExists = errors.Register(ModuleName, 5, "StorageProvider already exist for this pubkey; must use new StorageProvider pubkey")
ErrInsufficientDepositAmount = errors.Register(ModuleName, 6, "insufficient deposit amount")
ErrDepositAccountNotAllowed = errors.Register(ModuleName, 7, "the deposit address must be the sp address or the fund address of sp.")
ErrInvalidDepositDenom = errors.Register(ModuleName, 8, "the deposit address must be the sp address or the fund address of sp.")
ErrStoraveProviderFundingAddrExists = errors.Register(ModuleName, 9, "StorageProvider already exist for this funding address; must use new StorageProvider funding address.")
ErrStoraveProviderSealAddrExists = errors.Register(ModuleName, 10, "StorageProvider already exist for this seal address; must use new StorageProvider seal address.")
ErrStoraveProviderApprovalAddrExists = errors.Register(ModuleName, 11, "StorageProvider already exist for this approval address; must use new StorageProvider approval address.")
ErrStorageProviderNotFound = errors.Register(ModuleName, 1, "StorageProvider does not exist")
ErrStorageProviderNotInService = errors.Register(ModuleName, 2, "StorageProvider does not exist")
ErrStorageProviderOwnerExists = errors.Register(ModuleName, 3, "StorageProvider already exist for this operator address; must use new StorageProvider operator address")
ErrInsufficientDepositAmount = errors.Register(ModuleName, 4, "insufficient deposit amount")
ErrDepositAccountNotAllowed = errors.Register(ModuleName, 5, "the deposit address must be the sp address or the fund address of sp.")
ErrInvalidDepositDenom = errors.Register(ModuleName, 6, "the deposit address must be the sp address or the fund address of sp.")
ErrStorageProviderFundingAddrExists = errors.Register(ModuleName, 7, "StorageProvider already exist for this funding address; must use new StorageProvider funding address.")
ErrStorageProviderSealAddrExists = errors.Register(ModuleName, 8, "StorageProvider already exist for this seal address; must use new StorageProvider seal address.")
ErrStorageProviderApprovalAddrExists = errors.Register(ModuleName, 9, "StorageProvider already exist for this approval address; must use new StorageProvider approval address.")

ErrSignerNotGovModule = errors.Register(ModuleName, 40, "signer is not gov module account")
ErrSignerEmpty = errors.Register(ModuleName, 41, "signer is empty")
Expand Down
Loading

0 comments on commit 7c451df

Please sign in to comment.