diff --git a/go.mod b/go.mod index 83dfa825..9299d18e 100644 --- a/go.mod +++ b/go.mod @@ -17,6 +17,7 @@ require ( github.com/grpc-ecosystem/grpc-gateway v1.16.0 github.com/improbable-eng/grpc-web v0.15.0 github.com/ipfs/go-cid v0.1.0 + github.com/kelindar/bitmap v1.4.1 github.com/pkg/errors v0.9.1 github.com/rakyll/statik v0.1.7 github.com/regen-network/cosmos-proto v0.3.1 @@ -105,9 +106,10 @@ require ( github.com/inconshreveable/mousetrap v1.0.1 // indirect github.com/jackpal/go-nat-pmp v1.0.2 // indirect github.com/jmhodges/levigo v1.0.0 // indirect + github.com/kelindar/simd v1.1.2 // indirect github.com/keybase/go-keychain v0.0.0-20190712205309-48d3d31d256d // indirect github.com/klauspost/compress v1.15.11 // indirect - github.com/klauspost/cpuid/v2 v2.0.4 // indirect + github.com/klauspost/cpuid/v2 v2.0.12 // indirect github.com/lib/pq v1.10.6 // indirect github.com/libp2p/go-buffer-pool v0.1.0 // indirect github.com/magiconair/properties v1.8.6 // indirect diff --git a/go.sum b/go.sum index 80a95e03..65604235 100644 --- a/go.sum +++ b/go.sum @@ -516,6 +516,10 @@ github.com/julienschmidt/httprouter v1.1.1-0.20170430222011-975b5c4c7c21/go.mod github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= github.com/karalabe/usb v0.0.0-20190919080040-51dc0efba356/go.mod h1:Od972xHfMJowv7NGVDiWVxk2zxnWgjLlJzE+F4F7AGU= +github.com/kelindar/bitmap v1.4.1 h1:Ih0BWMYXkkZxPMU536DsQKRhdvqFl7tuNjImfLJWC6E= +github.com/kelindar/bitmap v1.4.1/go.mod h1:4QyD+TDbfgy8oYB9oC4JzqfudYCYIjhbSP7iLraP+28= +github.com/kelindar/simd v1.1.2 h1:KduKb+M9cMY2HIH8S/cdJyD+5n5EGgq+Aeeleos55To= +github.com/kelindar/simd v1.1.2/go.mod h1:inq4DFudC7W8L5fhxoeZflLRNpWSs0GNx6MlWFvuvr0= github.com/keybase/go-keychain v0.0.0-20190712205309-48d3d31d256d h1:Z+RDyXzjKE0i2sTjZ/b1uxiGtPhFy34Ou/Tk0qwN0kM= github.com/keybase/go-keychain v0.0.0-20190712205309-48d3d31d256d/go.mod h1:JJNrCn9otv/2QP4D7SMJBgaleKpOf66PnW6F5WGNRIc= github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= @@ -525,8 +529,9 @@ github.com/klauspost/compress v1.10.3/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYs github.com/klauspost/compress v1.11.7/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs= github.com/klauspost/compress v1.15.11 h1:Lcadnb3RKGin4FYM/orgq0qde+nc15E5Cbqg4B9Sx9c= github.com/klauspost/compress v1.15.11/go.mod h1:QPwzmACJjUTFsnSHH934V6woptycfrDDJnH7hvFVbGM= -github.com/klauspost/cpuid/v2 v2.0.4 h1:g0I61F2K2DjRHz1cnxlkNSBIaePVoJIjjnHui8QHbiw= github.com/klauspost/cpuid/v2 v2.0.4/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= +github.com/klauspost/cpuid/v2 v2.0.12 h1:p9dKCg8i4gmOxtv35DvrYoWqYzQrvEVdjQ762Y0OqZE= +github.com/klauspost/cpuid/v2 v2.0.12/go.mod h1:g2LTdtYhdyuGPqyWyv7qRAmj1WBqxuObKfj5c0PQa7c= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg= diff --git a/proto/stratos/sds/v1/genesis.proto b/proto/stratos/sds/v1/genesis.proto index 2f89aacf..a6137af3 100644 --- a/proto/stratos/sds/v1/genesis.proto +++ b/proto/stratos/sds/v1/genesis.proto @@ -8,16 +8,25 @@ option go_package = "github.com/stratosnet/stratos-chain/x/sds/types"; // GenesisState defines the register module's genesis state. message GenesisState { - Params params = 1 [ + Params params = 1 [ (gogoproto.jsontag) = "params", (gogoproto.moretags) = "yaml:\"params\"" ]; - repeated FileUpload file_uploads = 2 [ - (gogoproto.jsontag) = "file_uploads", - (gogoproto.moretags) = "yaml:\"file_uploads\"" + repeated GenesisFileInfo files = 2 [ + (gogoproto.nullable) = false, + (gogoproto.jsontag) = "files", + (gogoproto.moretags) = "yaml:\"files\"" ]; } - - - +message GenesisFileInfo { + string file_hash = 1 [ + (gogoproto.jsontag) = "file_hash", + (gogoproto.moretags) = "yaml:\"file_hash\"" + ]; + FileInfo file_info = 2 [ + (gogoproto.nullable) = false, + (gogoproto.jsontag) = "file_info", + (gogoproto.moretags) = "yaml:\"file_info\"" + ]; +} diff --git a/proto/stratos/sds/v1/sds.proto b/proto/stratos/sds/v1/sds.proto index 65e405c8..4aeb49d3 100644 --- a/proto/stratos/sds/v1/sds.proto +++ b/proto/stratos/sds/v1/sds.proto @@ -13,22 +13,19 @@ message Params { ]; } -message FileUpload { - string file_hash = 1 [ - (gogoproto.jsontag) = "file_hash", - (gogoproto.moretags) = "yaml:\"file_hash\"" - ]; - FileInfo file_info = 2 [ - (gogoproto.jsontag) = "file_info", - (gogoproto.moretags) = "yaml:\"file_info\"" - ]; -} - message FileInfo { - string height = 1 [ + string height = 1 [ + (gogoproto.nullable) = false, + (gogoproto.jsontag) = "height", + (gogoproto.moretags) = "yaml:\"height\"", (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int" ]; - string reporter = 2; - string uploader = 3; -} - + bytes reporters = 2 [ + (gogoproto.jsontag) = "reporters", + (gogoproto.moretags) = "yaml:\"reporters\"" + ]; + string uploader = 3 [ + (gogoproto.jsontag) = "uploader", + (gogoproto.moretags) = "yaml:\"uploader\"" + ]; +} \ No newline at end of file diff --git a/x/register/abci.go b/x/register/abci.go index 03773d7a..46a2cde6 100644 --- a/x/register/abci.go +++ b/x/register/abci.go @@ -1,18 +1,21 @@ package register import ( + abci "github.com/tendermint/tendermint/abci/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/stratosnet/stratos-chain/x/register/keeper" - abci "github.com/tendermint/tendermint/abci/types" ) // BeginBlocker check for infraction evidence or downtime of validators // on every begin block func BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock, k keeper.Keeper) { - // TODO: fill out if your application requires beginblock, if not you can delete this function + k.UpdateMetaNodeBitMapIdxCache(ctx) } // EndBlocker called every block, process inflation, update validator set. func EndBlocker(ctx sdk.Context, k keeper.Keeper) []abci.ValidatorUpdate { - return k.BlockRegisteredNodesUpdates(ctx) + k.BlockRegisteredNodesUpdates(ctx) + return []abci.ValidatorUpdate{} } diff --git a/x/register/genesis.go b/x/register/genesis.go index 6c24f0a6..33a7b3dd 100644 --- a/x/register/genesis.go +++ b/x/register/genesis.go @@ -3,6 +3,7 @@ package register import ( sdk "github.com/cosmos/cosmos-sdk/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + "github.com/stratosnet/stratos-chain/x/register/keeper" "github.com/stratosnet/stratos-chain/x/register/types" ) @@ -116,6 +117,9 @@ func InitGenesis(ctx sdk.Context, keeper keeper.Keeper, data *types.GenesisState keeper.SetSlashing(ctx, walletAddress, sdk.NewInt(slashing.Value)) } + + keeper.ReloadMetaNodeBitMapIdxCache(ctx) + return } diff --git a/x/register/keeper/keeper.go b/x/register/keeper/keeper.go index a69c7a03..7630fd06 100644 --- a/x/register/keeper/keeper.go +++ b/x/register/keeper/keeper.go @@ -6,6 +6,8 @@ import ( "fmt" "time" + "github.com/tendermint/tendermint/libs/log" + "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" @@ -14,23 +16,26 @@ import ( stratos "github.com/stratosnet/stratos-chain/types" "github.com/stratosnet/stratos-chain/x/register/types" regtypes "github.com/stratosnet/stratos-chain/x/register/types" - "github.com/tendermint/tendermint/libs/log" +) + +var ( + metaNodeBitMapIndexCacheStatus = types.CACHE_DIRTY ) // Keeper of the register store type Keeper struct { - storeKey sdk.StoreKey - cdc codec.Codec - // module specific parameter space that can be configured through governance - paramSpace paramtypes.Subspace - accountKeeper types.AccountKeeper - bankKeeper types.BankKeeper - distrKeeper types.DistrKeeper - hooks types.RegisterHooks - resourceNodeCache map[string]cachedResourceNode - resourceNodeCacheList *list.List - metaNodeCache map[string]cachedMetaNode - metaNodeCacheList *list.List + storeKey sdk.StoreKey + cdc codec.Codec + paramSpace paramtypes.Subspace + accountKeeper types.AccountKeeper + bankKeeper types.BankKeeper + distrKeeper types.DistrKeeper + hooks types.RegisterHooks + resourceNodeCache map[string]cachedResourceNode + resourceNodeCacheList *list.List + metaNodeCache map[string]cachedMetaNode + metaNodeCacheList *list.List + metaNodeBitMapIndexCache map[string]int } // NewKeeper creates a register keeper @@ -38,17 +43,18 @@ func NewKeeper(cdc codec.Codec, key sdk.StoreKey, paramSpace paramtypes.Subspace accountKeeper types.AccountKeeper, bankKeeper types.BankKeeper, distrKeeper types.DistrKeeper) Keeper { keeper := Keeper{ - storeKey: key, - cdc: cdc, - paramSpace: paramSpace.WithKeyTable(types.ParamKeyTable()), - accountKeeper: accountKeeper, - bankKeeper: bankKeeper, - distrKeeper: distrKeeper, - hooks: nil, - resourceNodeCache: make(map[string]cachedResourceNode, resourceNodeCacheSize), - resourceNodeCacheList: list.New(), - metaNodeCache: make(map[string]cachedMetaNode, metaNodeCacheSize), - metaNodeCacheList: list.New(), + storeKey: key, + cdc: cdc, + paramSpace: paramSpace.WithKeyTable(types.ParamKeyTable()), + accountKeeper: accountKeeper, + bankKeeper: bankKeeper, + distrKeeper: distrKeeper, + hooks: nil, + resourceNodeCache: make(map[string]cachedResourceNode, resourceNodeCacheSize), + resourceNodeCacheList: list.New(), + metaNodeCache: make(map[string]cachedMetaNode, metaNodeCacheSize), + metaNodeCacheList: list.New(), + metaNodeBitMapIndexCache: make(map[string]int), } return keeper } diff --git a/x/register/keeper/meta_node.go b/x/register/keeper/meta_node.go index f33fc38c..6178b2f5 100644 --- a/x/register/keeper/meta_node.go +++ b/x/register/keeper/meta_node.go @@ -2,6 +2,9 @@ package keeper import ( "bytes" + "errors" + "fmt" + "sort" "strings" "time" @@ -350,6 +353,9 @@ func (k Keeper) HandleVoteForMetaNodeRegistration(ctx sdk.Context, nodeAddr stra node.Status = stakingtypes.Bonded node.Suspend = false k.SetMetaNode(ctx, node) + // add new available meta node to cache + networkAddr, _ := stratos.SdsAddressFromBech32(node.GetNetworkAddress()) + k.AddMetaNodeToBitMapIdxCache(networkAddr) // increase ozone limit after vote is approved _ = k.IncreaseOzoneLimitByAddStake(ctx, node.Tokens) // increase mata node count @@ -474,3 +480,75 @@ func (k Keeper) OwnMetaNode(ctx sdk.Context, ownerAddr sdk.AccAddress, p2pAddr s } return true } + +func (k Keeper) GetMetaNodeBitMapIndex(ctx sdk.Context, networkAddr stratos.SdsAddress) (index int, err error) { + k.UpdateMetaNodeBitMapIdxCache(ctx) + + index, ok := k.metaNodeBitMapIndexCache[networkAddr.String()] + if !ok { + return index, errors.New(fmt.Sprintf("Can not find meta-node %v from cache", networkAddr.String())) + } + if index < 0 { + return index, errors.New(fmt.Sprintf("Can not find correct index of meta-node %v from cache", networkAddr.String())) + } + + return index, nil +} + +func (k Keeper) AddMetaNodeToBitMapIdxCache(networkAddr stratos.SdsAddress) { + k.metaNodeBitMapIndexCache[networkAddr.String()] = -1 + metaNodeBitMapIndexCacheStatus = types.CACHE_DIRTY +} + +func (k Keeper) RemoveMetaNodeFromBitMapIdxCache(networkAddr stratos.SdsAddress) { + delete(k.metaNodeBitMapIndexCache, networkAddr.String()) + metaNodeBitMapIndexCacheStatus = types.CACHE_DIRTY +} + +func (k Keeper) UpdateMetaNodeBitMapIdxCache(ctx sdk.Context) { + if metaNodeBitMapIndexCacheStatus == types.CACHE_NOT_DIRTY { + return + } + if len(k.metaNodeBitMapIndexCache) == 0 { + k.ReloadMetaNodeBitMapIdxCache(ctx) + return + } + + keys := make([]string, 0) + for key, _ := range k.metaNodeBitMapIndexCache { + keys = append(keys, key) + } + sort.Slice(keys, func(i, j int) bool { + return keys[i] < keys[j] + }) + for index, key := range keys { + k.metaNodeBitMapIndexCache[key] = index + } + metaNodeBitMapIndexCacheStatus = types.CACHE_NOT_DIRTY +} + +func (k Keeper) ReloadMetaNodeBitMapIdxCache(ctx sdk.Context) { + if metaNodeBitMapIndexCacheStatus == types.CACHE_NOT_DIRTY { + return + } + keys := make([]string, 0) + store := ctx.KVStore(k.storeKey) + iterator := sdk.KVStorePrefixIterator(store, types.MetaNodeKey) + defer iterator.Close() + + for ; iterator.Valid(); iterator.Next() { + node := types.MustUnmarshalMetaNode(k.cdc, iterator.Value()) + if node.GetSuspend() || node.GetStatus() == stakingtypes.Unbonded { + continue + } + keys = append(keys, node.GetNetworkAddress()) + } + + sort.Slice(keys, func(i, j int) bool { + return keys[i] < keys[j] + }) + for index, key := range keys { + k.metaNodeBitMapIndexCache[key] = index + } + metaNodeBitMapIndexCacheStatus = types.CACHE_NOT_DIRTY +} diff --git a/x/register/keeper/node_state_change.go b/x/register/keeper/node_state_change.go index 7e3e8669..c9555ee0 100644 --- a/x/register/keeper/node_state_change.go +++ b/x/register/keeper/node_state_change.go @@ -6,13 +6,13 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + stratos "github.com/stratosnet/stratos-chain/types" "github.com/stratosnet/stratos-chain/x/register/types" - abci "github.com/tendermint/tendermint/abci/types" ) // Called in each EndBlock -func (k Keeper) BlockRegisteredNodesUpdates(ctx sdk.Context) []abci.ValidatorUpdate { +func (k Keeper) BlockRegisteredNodesUpdates(ctx sdk.Context) { // Remove all mature unbonding nodes from the ubd queue. ctx.Logger().Debug("Enter BlockRegisteredNodesUpdates") matureUBDs := k.DequeueAllMatureUBDQueue(ctx, ctx.BlockHeader().Time) @@ -42,7 +42,7 @@ func (k Keeper) BlockRegisteredNodesUpdates(ctx sdk.Context) []abci.ValidatorUpd } // UpdateNode won't create UBD node - return []abci.ValidatorUpdate{} + return } // Node state transitions @@ -135,6 +135,8 @@ func (k Keeper) completeUnbondingNode(ctx sdk.Context, node interface{}, isMetaN temp := node.(types.MetaNode) temp.Status = stakingtypes.Unbonded k.SetMetaNode(ctx, temp) + networkAddr, _ := stratos.SdsAddressFromBech32(temp.GetNetworkAddress()) + k.RemoveMetaNodeFromBitMapIdxCache(networkAddr) return temp } else { temp := node.(types.ResourceNode) diff --git a/x/register/types/meta_node.go b/x/register/types/meta_node.go index 2eeb9675..a98fbad2 100644 --- a/x/register/types/meta_node.go +++ b/x/register/types/meta_node.go @@ -14,6 +14,13 @@ import ( stratos "github.com/stratosnet/stratos-chain/types" ) +type CacheStatus uint8 + +const ( + CACHE_NOT_DIRTY CacheStatus = 0 + CACHE_DIRTY CacheStatus = 1 +) + // NewMetaNode - initialize a new meta node func NewMetaNode(networkAddr stratos.SdsAddress, pubKey cryptotypes.PubKey, ownerAddr sdk.AccAddress, description *Description, creationTime time.Time) (MetaNode, error) { pkAny, err := codectypes.NewAnyWithValue(pubKey) diff --git a/x/sds/client/cli/tx.go b/x/sds/client/cli/tx.go index baa379b9..c6e6b149 100644 --- a/x/sds/client/cli/tx.go +++ b/x/sds/client/cli/tx.go @@ -1,7 +1,6 @@ package cli import ( - "encoding/hex" "fmt" "github.com/cosmos/cosmos-sdk/client/tx" @@ -108,10 +107,6 @@ func newBuildFileuploadMsg(clientCtx client.Context, txf tx.Factory, fs *flag.Fl if err != nil { return txf, nil, err } - _, err = hex.DecodeString(fileHash) - if err != nil { - return txf, nil, err - } flagReporterStr, err := fs.GetString(FlagReporter) if err != nil { diff --git a/x/sds/genesis.go b/x/sds/genesis.go index efd0b708..0ce480dd 100644 --- a/x/sds/genesis.go +++ b/x/sds/genesis.go @@ -2,6 +2,7 @@ package sds import ( sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/stratosnet/stratos-chain/x/sds/keeper" "github.com/stratosnet/stratos-chain/x/sds/types" ) @@ -11,8 +12,8 @@ import ( func InitGenesis(ctx sdk.Context, keeper keeper.Keeper, data *types.GenesisState) { keeper.SetParams(ctx, *data.Params) - for _, file := range data.GetFileUploads() { - keeper.SetFileHash(ctx, []byte(file.FileHash), *file.FileInfo) + for _, file := range data.GetFiles() { + keeper.SetFileInfo(ctx, []byte(file.FileHash), file.GetFileInfo()) } return } @@ -23,11 +24,11 @@ func InitGenesis(ctx sdk.Context, keeper keeper.Keeper, data *types.GenesisState func ExportGenesis(ctx sdk.Context, keeper keeper.Keeper) (data types.GenesisState) { params := keeper.GetParams(ctx) - var fileUpload []*types.FileUpload - keeper.IterateFileUpload(ctx, func(fileHash string, fileInfo types.FileInfo) (stop bool) { - fileUpload = append(fileUpload, &types.FileUpload{FileHash: fileHash, FileInfo: &fileInfo}) + var files []types.GenesisFileInfo + keeper.IterateFileInfo(ctx, func(fileHash string, fileInfo types.FileInfo) (stop bool) { + files = append(files, types.GenesisFileInfo{FileHash: fileHash, FileInfo: fileInfo}) return false }) - return types.NewGenesisState(¶ms, fileUpload) + return types.NewGenesisState(¶ms, files) } diff --git a/x/sds/keeper/grpc_query.go b/x/sds/keeper/grpc_query.go index 3b70c574..8815abb6 100644 --- a/x/sds/keeper/grpc_query.go +++ b/x/sds/keeper/grpc_query.go @@ -2,13 +2,15 @@ package keeper import ( "context" - "encoding/hex" "fmt" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/stratosnet/stratos-chain/x/sds/types" + "github.com/ipfs/go-cid" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" + + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/stratosnet/stratos-chain/x/sds/types" ) var _ types.QueryServer = Querier{} @@ -27,19 +29,16 @@ func (q Querier) Fileupload(c context.Context, req *types.QueryFileUploadRequest return &types.QueryFileUploadResponse{}, status.Error(codes.InvalidArgument, " Network address cannot be empty") } - ctx := sdk.UnwrapSDKContext(c) - - _, err := hex.DecodeString(req.GetFileHash()) - if err != nil { - return &types.QueryFileUploadResponse{}, fmt.Errorf("invalid file hash, please specify a hash in hex format %w", err) - } - fileInfoBytes, err := q.GetFileInfoBytesByFileHash(ctx, []byte(req.GetFileHash())) + _, err := cid.Decode(req.GetFileHash()) if err != nil { - return &types.QueryFileUploadResponse{}, err + return &types.QueryFileUploadResponse{}, fmt.Errorf("invalid file hash %w", err) } - fileInfo, err := types.UnmarshalFileInfo(q.cdc, fileInfoBytes) - if err != nil { - return &types.QueryFileUploadResponse{}, err + + ctx := sdk.UnwrapSDKContext(c) + + fileInfo, found := q.GetFileInfoByFileHash(ctx, []byte(req.GetFileHash())) + if !found { + return &types.QueryFileUploadResponse{}, types.ErrNoFileFound } return &types.QueryFileUploadResponse{FileInfo: &fileInfo}, nil diff --git a/x/sds/keeper/keeper.go b/x/sds/keeper/keeper.go index 30a9087e..0cfa1636 100644 --- a/x/sds/keeper/keeper.go +++ b/x/sds/keeper/keeper.go @@ -1,9 +1,10 @@ package keeper import ( - "encoding/hex" "fmt" + "github.com/kelindar/bitmap" + "github.com/tendermint/tendermint/libs/log" "github.com/cosmos/cosmos-sdk/codec" @@ -12,6 +13,7 @@ import ( bankKeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" + stratos "github.com/stratosnet/stratos-chain/types" potKeeper "github.com/stratosnet/stratos-chain/x/pot/keeper" registerKeeper "github.com/stratosnet/stratos-chain/x/register/keeper" registertypes "github.com/stratosnet/stratos-chain/x/register/types" @@ -55,22 +57,28 @@ func (k Keeper) Logger(ctx sdk.Context) log.Logger { return ctx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName)) } -// GetFileInfoBytesByFileHash Returns the hash of file -func (k Keeper) GetFileInfoBytesByFileHash(ctx sdk.Context, key []byte) ([]byte, error) { - store := ctx.KVStore(k.key) - bz := store.Get(types.FileStoreKey(key)) - if bz == nil { - return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownAddress, "FileHash %s does not exist", hex.EncodeToString(types.FileStoreKey(key))[2:]) +func (k Keeper) FileUpload(ctx sdk.Context, fileHash string, reporter stratos.SdsAddress, reporterOwner, uploader sdk.AccAddress) (err error) { + if !(k.registerKeeper.OwnMetaNode(ctx, reporterOwner, reporter)) { + return types.ErrReporterAddressOrOwner } - return bz, nil -} -// SetFileHash Sets sender-fileHash KV pair -func (k Keeper) SetFileHash(ctx sdk.Context, fileHash []byte, fileInfo types.FileInfo) { - store := ctx.KVStore(k.key) - storeKey := types.FileStoreKey(fileHash) - bz := types.MustMarshalFileInfo(k.cdc, fileInfo) - store.Set(storeKey, bz) + var fileUploadReporters bitmap.Bitmap + // query exist fileInfo which sent by other meta node + fileInfo, found := k.GetFileInfoByFileHash(ctx, []byte(fileHash)) + if !found { + fileUploadReporters = bitmap.Bitmap{} + } else { + fileUploadReporters = bitmap.FromBytes(fileInfo.GetReporters()) + } + reporterIndex, err := k.registerKeeper.GetMetaNodeBitMapIndex(ctx, reporter) + fileUploadReporters.Set(uint32(reporterIndex)) + height := sdk.NewInt(ctx.BlockHeight()) + + newFileInfo := types.NewFileInfo(height, fileUploadReporters.ToBytes(), uploader.String()) + + k.SetFileInfo(ctx, []byte(fileHash), newFileInfo) + + return nil } // [S] is the initial genesis deposit by all Resource Nodes and Meta Nodes at t=0 @@ -131,19 +139,3 @@ func (k Keeper) Prepay(ctx sdk.Context, sender sdk.AccAddress, coins sdk.Coins) prepay := coins.AmountOf(k.BondDenom(ctx)) return k.purchaseNozAndSubCoins(ctx, sender, prepay) } - -// IterateFileUpload Iterate over all uploaded files. -// Iteration for all uploaded files -func (k Keeper) IterateFileUpload(ctx sdk.Context, handler func(string, types.FileInfo) (stop bool)) { - store := ctx.KVStore(k.key) - iter := sdk.KVStorePrefixIterator(store, types.FileStoreKeyPrefix) - defer iter.Close() - for ; iter.Valid(); iter.Next() { - fileHash := string(iter.Key()[len(types.FileStoreKeyPrefix):]) - var fileInfo types.FileInfo - k.cdc.MustUnmarshal(iter.Value(), &fileInfo) - if handler(fileHash, fileInfo) { - break - } - } -} diff --git a/x/sds/keeper/msg_server.go b/x/sds/keeper/msg_server.go index 2d92bcdf..9fa05a09 100644 --- a/x/sds/keeper/msg_server.go +++ b/x/sds/keeper/msg_server.go @@ -5,6 +5,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + stratos "github.com/stratosnet/stratos-chain/types" "github.com/stratosnet/stratos-chain/x/sds/types" ) @@ -30,20 +31,20 @@ func (k msgServer) HandleMsgFileUpload(c context.Context, msg *types.MsgFileUplo return &types.MsgFileUploadResponse{}, sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, err.Error()) } - if _, found := k.registerKeeper.GetMetaNode(ctx, reporter); found == false { - return nil, sdkerrors.Wrapf(sdkerrors.ErrUnauthorized, "Reporter %s isn't an SP node", msg.GetReporter()) + reporterOwner, err := sdk.AccAddressFromBech32(msg.GetFrom()) + if err != nil { + return &types.MsgFileUploadResponse{}, sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, err.Error()) } - height := sdk.NewInt(ctx.BlockHeight()) - heightByteArr, _ := height.MarshalJSON() - var heightReEncoded sdk.Int - err = heightReEncoded.UnmarshalJSON(heightByteArr) + + uploader, err := sdk.AccAddressFromBech32(msg.Uploader) if err != nil { - return &types.MsgFileUploadResponse{}, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) + return &types.MsgFileUploadResponse{}, sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, err.Error()) } - fileInfo := types.NewFileInfo(&heightReEncoded, msg.Reporter, msg.Uploader) - fileHashByte := []byte(msg.FileHash) - k.SetFileHash(ctx, fileHashByte, fileInfo) + err = k.FileUpload(ctx, msg.GetFileHash(), reporter, reporterOwner, uploader) + if err != nil { + return &types.MsgFileUploadResponse{}, err + } ctx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( diff --git a/x/sds/keeper/querier.go b/x/sds/keeper/querier.go index e819ef75..7a90d36a 100644 --- a/x/sds/keeper/querier.go +++ b/x/sds/keeper/querier.go @@ -4,14 +4,13 @@ import ( "encoding/hex" "encoding/json" - "github.com/cosmos/cosmos-sdk/codec" - "github.com/stratosnet/stratos-chain/x/sds/types" - - // this line is used by starport scaffolding # 1 abci "github.com/tendermint/tendermint/abci/types" + "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + + "github.com/stratosnet/stratos-chain/x/sds/types" ) // NewQuerier creates a new querier for sds clients. @@ -45,13 +44,16 @@ func getSdsParams(ctx sdk.Context, req abci.RequestQuery, k Keeper, legacyQuerie } // queryFileHash fetch a file's hash for the supplied height. -func queryUploadedFileByHash(ctx sdk.Context, req abci.RequestQuery, k Keeper, _ *codec.LegacyAmino) ([]byte, error) { - fileInfo, err := k.GetFileInfoBytesByFileHash(ctx, req.Data) +func queryUploadedFileByHash(ctx sdk.Context, req abci.RequestQuery, k Keeper, legacyQuerierCdc *codec.LegacyAmino) ([]byte, error) { + fileInfo, found := k.GetFileInfoByFileHash(ctx, req.Data) + if !found { + return nil, types.ErrNoFileFound + } + res, err := codec.MarshalJSONIndent(legacyQuerierCdc, fileInfo) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } - - return fileInfo, nil + return res, nil } // querySimulatePrepay fetch amt of noz with a simulated prepay of X wei. diff --git a/x/sds/keeper/store.go b/x/sds/keeper/store.go new file mode 100644 index 00000000..16b4a9d2 --- /dev/null +++ b/x/sds/keeper/store.go @@ -0,0 +1,41 @@ +package keeper + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/stratosnet/stratos-chain/x/sds/types" +) + +// GetFileInfoByFileHash Returns the fileInfo +func (k Keeper) GetFileInfoByFileHash(ctx sdk.Context, fileHash []byte) (fileInfo types.FileInfo, found bool) { + store := ctx.KVStore(k.key) + bz := store.Get(types.FileStoreKey(fileHash)) + if bz == nil { + return fileInfo, false + } + k.cdc.MustUnmarshalLengthPrefixed(bz, &fileInfo) + return fileInfo, true +} + +func (k Keeper) SetFileInfo(ctx sdk.Context, fileHash []byte, fileInfo types.FileInfo) { + store := ctx.KVStore(k.key) + storeKey := types.FileStoreKey(fileHash) + bz := k.cdc.MustMarshalLengthPrefixed(&fileInfo) + store.Set(storeKey, bz) +} + +// IterateFileInfo Iterate over all uploaded files. +// Iteration for all uploaded files +func (k Keeper) IterateFileInfo(ctx sdk.Context, handler func(string, types.FileInfo) (stop bool)) { + store := ctx.KVStore(k.key) + iter := sdk.KVStorePrefixIterator(store, types.FileStoreKeyPrefix) + defer iter.Close() + for ; iter.Valid(); iter.Next() { + fileHash := string(iter.Key()[len(types.FileStoreKeyPrefix):]) + var fileInfo types.FileInfo + k.cdc.MustUnmarshalLengthPrefixed(iter.Value(), &fileInfo) + if handler(fileHash, fileInfo) { + break + } + } +} diff --git a/x/sds/types/errors.go b/x/sds/types/errors.go index 24b93369..5998c77b 100644 --- a/x/sds/types/errors.go +++ b/x/sds/types/errors.go @@ -9,21 +9,25 @@ const ( codeErrInvalidHeight codeErrEmptyUploaderAddr codeErrEmptyReporterAddr + codeErrEmptyReporters codeErrEmptyFileHash - codeErrInvalidCoins codeErrInvalidFileHash + codeErrNoFileFound codeErrInvalidDenom codeErrPrepayFailure + codeErrReporterAddressOrOwner ) var ( - ErrInvalid = sdkerrors.Register(ModuleName, codeErrInvalid, "error invalid") - ErrInvalidHeight = sdkerrors.Register(ModuleName, codeErrInvalidHeight, "invalid height") - ErrEmptyUploaderAddr = sdkerrors.Register(ModuleName, codeErrEmptyUploaderAddr, "missing uploader address") - ErrEmptyReporterAddr = sdkerrors.Register(ModuleName, codeErrEmptyReporterAddr, "missing reporter address") - ErrEmptyFileHash = sdkerrors.Register(ModuleName, codeErrEmptyFileHash, "missing file hash") - ErrInvalidCoins = sdkerrors.Register(ModuleName, codeErrInvalidCoins, "invalid coins") - ErrInvalidFileHash = sdkerrors.Register(ModuleName, codeErrInvalidFileHash, "invalid file hash") - ErrInvalidDenom = sdkerrors.Register(ModuleName, codeErrInvalidDenom, "invalid denomination") - ErrPrepayFailure = sdkerrors.Register(ModuleName, codeErrPrepayFailure, "failure during prepay") + ErrInvalid = sdkerrors.Register(ModuleName, codeErrInvalid, "error invalid") + ErrInvalidHeight = sdkerrors.Register(ModuleName, codeErrInvalidHeight, "invalid height") + ErrEmptyUploaderAddr = sdkerrors.Register(ModuleName, codeErrEmptyUploaderAddr, "missing uploader address") + ErrEmptyReporterAddr = sdkerrors.Register(ModuleName, codeErrEmptyReporterAddr, "missing reporter address") + ErrEmptyReporters = sdkerrors.Register(ModuleName, codeErrEmptyReporters, "missing reporters") + ErrEmptyFileHash = sdkerrors.Register(ModuleName, codeErrEmptyFileHash, "missing file hash") + ErrInvalidFileHash = sdkerrors.Register(ModuleName, codeErrInvalidFileHash, "invalid file hash") + ErrNoFileFound = sdkerrors.Register(ModuleName, codeErrNoFileFound, "file does not exist") + ErrInvalidDenom = sdkerrors.Register(ModuleName, codeErrInvalidDenom, "invalid denomination") + ErrPrepayFailure = sdkerrors.Register(ModuleName, codeErrPrepayFailure, "failure during prepay") + ErrReporterAddressOrOwner = sdkerrors.Register(ModuleName, codeErrReporterAddressOrOwner, "invalid reporter address or owner address") ) diff --git a/x/sds/types/genesis.go b/x/sds/types/genesis.go index 3298509a..449c6485 100644 --- a/x/sds/types/genesis.go +++ b/x/sds/types/genesis.go @@ -8,10 +8,10 @@ import ( ) // NewGenesisState creates a new GenesisState object -func NewGenesisState(params *Params, fileUploads []*FileUpload) GenesisState { +func NewGenesisState(params *Params, files []GenesisFileInfo) GenesisState { return GenesisState{ - Params: params, - FileUploads: fileUploads, + Params: params, + Files: files, } } @@ -39,18 +39,18 @@ func ValidateGenesis(data GenesisState) error { return err } - if len(data.FileUploads) > 0 { - for _, upload := range data.FileUploads { - if len(upload.FileHash) == 0 { + if len(data.GetFiles()) > 0 { + for _, file := range data.GetFiles() { + if len(file.FileHash) == 0 { return ErrEmptyFileHash } - if upload.FileInfo.Height.LT(sdk.ZeroInt()) { + if file.FileInfo.Height.LT(sdk.ZeroInt()) { return ErrInvalidHeight } - if len(upload.FileInfo.Reporter) == 0 { - return ErrEmptyReporterAddr + if len(file.FileInfo.Reporters) == 0 { + return ErrEmptyReporters } - if len(upload.FileInfo.Uploader) == 0 { + if len(file.FileInfo.Uploader) == 0 { return ErrEmptyUploaderAddr } } diff --git a/x/sds/types/genesis.pb.go b/x/sds/types/genesis.pb.go index c84d92d2..9039cce6 100644 --- a/x/sds/types/genesis.pb.go +++ b/x/sds/types/genesis.pb.go @@ -25,8 +25,8 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // GenesisState defines the register module's genesis state. type GenesisState struct { - Params *Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params" yaml:"params"` - FileUploads []*FileUpload `protobuf:"bytes,2,rep,name=file_uploads,json=fileUploads,proto3" json:"file_uploads" yaml:"file_uploads"` + Params *Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params" yaml:"params"` + Files []GenesisFileInfo `protobuf:"bytes,2,rep,name=files,proto3" json:"files" yaml:"files"` } func (m *GenesisState) Reset() { *m = GenesisState{} } @@ -69,38 +69,96 @@ func (m *GenesisState) GetParams() *Params { return nil } -func (m *GenesisState) GetFileUploads() []*FileUpload { +func (m *GenesisState) GetFiles() []GenesisFileInfo { if m != nil { - return m.FileUploads + return m.Files } return nil } +type GenesisFileInfo struct { + FileHash string `protobuf:"bytes,1,opt,name=file_hash,json=fileHash,proto3" json:"file_hash" yaml:"file_hash"` + FileInfo FileInfo `protobuf:"bytes,2,opt,name=file_info,json=fileInfo,proto3" json:"file_info" yaml:"file_info"` +} + +func (m *GenesisFileInfo) Reset() { *m = GenesisFileInfo{} } +func (m *GenesisFileInfo) String() string { return proto.CompactTextString(m) } +func (*GenesisFileInfo) ProtoMessage() {} +func (*GenesisFileInfo) Descriptor() ([]byte, []int) { + return fileDescriptor_a3396301dd7676d6, []int{1} +} +func (m *GenesisFileInfo) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *GenesisFileInfo) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_GenesisFileInfo.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *GenesisFileInfo) XXX_Merge(src proto.Message) { + xxx_messageInfo_GenesisFileInfo.Merge(m, src) +} +func (m *GenesisFileInfo) XXX_Size() int { + return m.Size() +} +func (m *GenesisFileInfo) XXX_DiscardUnknown() { + xxx_messageInfo_GenesisFileInfo.DiscardUnknown(m) +} + +var xxx_messageInfo_GenesisFileInfo proto.InternalMessageInfo + +func (m *GenesisFileInfo) GetFileHash() string { + if m != nil { + return m.FileHash + } + return "" +} + +func (m *GenesisFileInfo) GetFileInfo() FileInfo { + if m != nil { + return m.FileInfo + } + return FileInfo{} +} + func init() { proto.RegisterType((*GenesisState)(nil), "stratos.sds.v1.GenesisState") + proto.RegisterType((*GenesisFileInfo)(nil), "stratos.sds.v1.GenesisFileInfo") } func init() { proto.RegisterFile("stratos/sds/v1/genesis.proto", fileDescriptor_a3396301dd7676d6) } var fileDescriptor_a3396301dd7676d6 = []byte{ - // 271 bytes of a gzipped FileDescriptorProto + // 344 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00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7, 0xe4, 0x05, 0x10, 0x86, 0x81, 0x85, 0x94, + 0x82, 0x38, 0x40, 0x6c, 0x8f, 0xc4, 0xe2, 0x0c, 0xa1, 0x18, 0xa8, 0xfe, 0xcc, 0xbc, 0xb4, 0x7c, + 0x09, 0x26, 0xb0, 0xcf, 0x25, 0xd0, 0x5d, 0x0b, 0x77, 0xa6, 0x2a, 0xd4, 0x99, 0x08, 0x2d, 0x68, + 0xa6, 0x83, 0x84, 0xa0, 0xa6, 0x83, 0x35, 0x78, 0x9e, 0x78, 0x24, 0xc7, 0x78, 0xe1, 0x91, 0x1c, + 0xe3, 0x83, 0x47, 0x72, 0x8c, 0x13, 0x1e, 0xcb, 0x31, 0x5c, 0x78, 0x2c, 0xc7, 0x70, 0xe3, 0xb1, + 0x1c, 0x43, 0x94, 0x7e, 0x7a, 0x66, 0x49, 0x46, 0x69, 0x92, 0x5e, 0x72, 0x7e, 0xae, 0x3e, 0xd4, + 0xba, 0xbc, 0xd4, 0x12, 0x18, 0x53, 0x37, 0x39, 0x23, 0x31, 0x33, 0x4f, 0xbf, 0x02, 0x1c, 0x6f, + 0x25, 0x95, 0x05, 0xa9, 0xc5, 0x49, 0x6c, 0xe0, 0x78, 0x33, 0x06, 0x04, 0x00, 0x00, 0xff, 0xff, + 0x10, 0x41, 0x42, 0x04, 0x17, 0x02, 0x00, 0x00, } func (m *GenesisState) Marshal() (dAtA []byte, err error) { @@ -123,10 +181,10 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if len(m.FileUploads) > 0 { - for iNdEx := len(m.FileUploads) - 1; iNdEx >= 0; iNdEx-- { + if len(m.Files) > 0 { + for iNdEx := len(m.Files) - 1; iNdEx >= 0; iNdEx-- { { - size, err := m.FileUploads[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + size, err := m.Files[iNdEx].MarshalToSizedBuffer(dAtA[:i]) if err != nil { return 0, err } @@ -152,6 +210,46 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *GenesisFileInfo) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *GenesisFileInfo) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *GenesisFileInfo) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.FileInfo.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + if len(m.FileHash) > 0 { + i -= len(m.FileHash) + copy(dAtA[i:], m.FileHash) + i = encodeVarintGenesis(dAtA, i, uint64(len(m.FileHash))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + func encodeVarintGenesis(dAtA []byte, offset int, v uint64) int { offset -= sovGenesis(v) base := offset @@ -173,8 +271,8 @@ func (m *GenesisState) Size() (n int) { l = m.Params.Size() n += 1 + l + sovGenesis(uint64(l)) } - if len(m.FileUploads) > 0 { - for _, e := range m.FileUploads { + if len(m.Files) > 0 { + for _, e := range m.Files { l = e.Size() n += 1 + l + sovGenesis(uint64(l)) } @@ -182,6 +280,21 @@ func (m *GenesisState) Size() (n int) { return n } +func (m *GenesisFileInfo) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.FileHash) + if l > 0 { + n += 1 + l + sovGenesis(uint64(l)) + } + l = m.FileInfo.Size() + n += 1 + l + sovGenesis(uint64(l)) + return n +} + func sovGenesis(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -255,7 +368,123 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 2: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field FileUploads", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Files", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Files = append(m.Files, GenesisFileInfo{}) + if err := m.Files[len(m.Files)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipGenesis(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthGenesis + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *GenesisFileInfo) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: GenesisFileInfo: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: GenesisFileInfo: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field FileHash", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.FileHash = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field FileInfo", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -282,8 +511,7 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.FileUploads = append(m.FileUploads, &FileUpload{}) - if err := m.FileUploads[len(m.FileUploads)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + if err := m.FileInfo.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex diff --git a/x/sds/types/sds.pb.go b/x/sds/types/sds.pb.go index 87aaeb94..d9a3bcd4 100644 --- a/x/sds/types/sds.pb.go +++ b/x/sds/types/sds.pb.go @@ -69,69 +69,17 @@ func (m *Params) GetBondDenom() string { return "" } -type FileUpload struct { - FileHash string `protobuf:"bytes,1,opt,name=file_hash,json=fileHash,proto3" json:"file_hash" yaml:"file_hash"` - FileInfo *FileInfo `protobuf:"bytes,2,opt,name=file_info,json=fileInfo,proto3" json:"file_info" yaml:"file_info"` -} - -func (m *FileUpload) Reset() { *m = FileUpload{} } -func (m *FileUpload) String() string { return proto.CompactTextString(m) } -func (*FileUpload) ProtoMessage() {} -func (*FileUpload) Descriptor() ([]byte, []int) { - return fileDescriptor_a89f3959b8649eb2, []int{1} -} -func (m *FileUpload) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *FileUpload) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_FileUpload.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *FileUpload) XXX_Merge(src proto.Message) { - xxx_messageInfo_FileUpload.Merge(m, src) -} -func (m *FileUpload) XXX_Size() int { - return m.Size() -} -func (m *FileUpload) XXX_DiscardUnknown() { - xxx_messageInfo_FileUpload.DiscardUnknown(m) -} - -var xxx_messageInfo_FileUpload proto.InternalMessageInfo - -func (m *FileUpload) GetFileHash() string { - if m != nil { - return m.FileHash - } - return "" -} - -func (m *FileUpload) GetFileInfo() *FileInfo { - if m != nil { - return m.FileInfo - } - return nil -} - type FileInfo struct { - Height *github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,1,opt,name=height,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"height,omitempty"` - Reporter string `protobuf:"bytes,2,opt,name=reporter,proto3" json:"reporter,omitempty"` - Uploader string `protobuf:"bytes,3,opt,name=uploader,proto3" json:"uploader,omitempty"` + Height github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,1,opt,name=height,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"height" yaml:"height"` + Reporters []byte `protobuf:"bytes,2,opt,name=reporters,proto3" json:"reporters" yaml:"reporters"` + Uploader string `protobuf:"bytes,3,opt,name=uploader,proto3" json:"uploader" yaml:"uploader"` } func (m *FileInfo) Reset() { *m = FileInfo{} } func (m *FileInfo) String() string { return proto.CompactTextString(m) } func (*FileInfo) ProtoMessage() {} func (*FileInfo) Descriptor() ([]byte, []int) { - return fileDescriptor_a89f3959b8649eb2, []int{2} + return fileDescriptor_a89f3959b8649eb2, []int{1} } func (m *FileInfo) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -160,11 +108,11 @@ func (m *FileInfo) XXX_DiscardUnknown() { var xxx_messageInfo_FileInfo proto.InternalMessageInfo -func (m *FileInfo) GetReporter() string { +func (m *FileInfo) GetReporters() []byte { if m != nil { - return m.Reporter + return m.Reporters } - return "" + return nil } func (m *FileInfo) GetUploader() string { @@ -176,37 +124,34 @@ func (m *FileInfo) GetUploader() string { func init() { proto.RegisterType((*Params)(nil), "stratos.sds.v1.Params") - proto.RegisterType((*FileUpload)(nil), "stratos.sds.v1.FileUpload") proto.RegisterType((*FileInfo)(nil), "stratos.sds.v1.FileInfo") } func init() { proto.RegisterFile("stratos/sds/v1/sds.proto", fileDescriptor_a89f3959b8649eb2) } var fileDescriptor_a89f3959b8649eb2 = []byte{ - // 364 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x5c, 0x51, 0x4d, 0x4b, 0xeb, 0x40, - 0x14, 0xed, 0xbc, 0x07, 0xa5, 0x99, 0x07, 0x8f, 0xf7, 0x82, 0x8b, 0xd0, 0x45, 0x52, 0x23, 0x48, - 0x11, 0x9a, 0x50, 0xdd, 0xb9, 0x70, 0x11, 0x44, 0x2c, 0xb8, 0x90, 0x80, 0x20, 0x6e, 0xca, 0xb4, - 0x99, 0x26, 0xc1, 0x24, 0x37, 0xcc, 0x4c, 0x8b, 0xfd, 0x03, 0xae, 0xfd, 0x15, 0xfe, 0x16, 0x97, - 0x5d, 0x8a, 0x8b, 0x20, 0xed, 0xae, 0xcb, 0xfe, 0x02, 0x99, 0xe9, 0xf4, 0x43, 0x57, 0x73, 0xee, - 0x39, 0xf7, 0x9e, 0x9c, 0x9b, 0x8b, 0x2d, 0x2e, 0x18, 0x11, 0xc0, 0x7d, 0x1e, 0x71, 0x7f, 0xd2, - 0x95, 0x8f, 0x57, 0x32, 0x10, 0x60, 0xfe, 0xd5, 0x8a, 0x27, 0xa9, 0x49, 0xb7, 0x79, 0x10, 0x43, - 0x0c, 0x4a, 0xf2, 0x25, 0x5a, 0x77, 0xb9, 0x37, 0xb8, 0x7e, 0x4b, 0x18, 0xc9, 0xb9, 0x19, 0x60, - 0x3c, 0x80, 0x22, 0xea, 0x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, 0x6d, 0xf4, 0xb2, 0xb0, 0x6b, 0xb3, - 0x85, 0x5d, 0x7b, 0x5f, 0xd8, 0xb5, 0x07, 0x7f, 0x2f, 0x81, 0xde, 0xb9, 0xa0, 0x62, 0x03, 0x3b, - 0xc3, 0x84, 0xa4, 0x85, 0xff, 0xa4, 0xee, 0xae, 0xe2, 0x0c, 0xea, 0xea, 0xa2, 0x67, 0x5f, 0x01, - 0x00, 0x00, 0xff, 0xff, 0x8e, 0xcc, 0x78, 0xb5, 0x13, 0x02, 0x00, 0x00, + // 334 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x4c, 0x91, 0x3d, 0x6b, 0xeb, 0x30, + 0x14, 0x86, 0xad, 0x7b, 0x21, 0x24, 0xe2, 0xde, 0x7e, 0x98, 0x0e, 0xa6, 0x83, 0x95, 0xba, 0x50, + 0xb2, 0xc4, 0x22, 0x74, 0x6b, 0x87, 0x82, 0x29, 0x05, 0x43, 0x87, 0xe2, 0xb1, 0x4b, 0x51, 0x62, + 0xd5, 0x36, 0x8d, 0x7d, 0x8c, 0xa4, 0x84, 0xe6, 0x5f, 0xf4, 0x67, 0x65, 0xcc, 0x58, 0x3a, 0x88, + 0x92, 0x6c, 0xee, 0xe6, 0x5f, 0x50, 0xfc, 0x91, 0x8f, 0xe9, 0x9c, 0xf3, 0xbc, 0x7a, 0x25, 0x1d, + 0x5e, 0x6c, 0x49, 0x25, 0x98, 0x02, 0x49, 0x65, 0x28, 0xe9, 0x7c, 0x54, 0x15, 0x37, 0x17, 0xa0, + 0xc0, 0x3c, 0x6a, 0x15, 0xb7, 0x42, 0xf3, 0xd1, 0xf9, 0x59, 0x04, 0x11, 0xd4, 0x12, 0xad, 0xba, + 0xe6, 0x94, 0xf3, 0x88, 0x3b, 0x4f, 0x4c, 0xb0, 0x54, 0x9a, 0x1e, 0xc6, 0x63, 0xc8, 0xc2, 0x97, + 0x90, 0x67,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x66, 0xf5, 0xbe, 0xe3, 0x4e, 0x9d, 0xc6, 0xf5, + 0x6f, 0x00, 0x00, 0x00, 0xff, 0xff, 0xd6, 0xc6, 0x4f, 0x7b, 0xcf, 0x01, 0x00, 0x00, } func (m *Params) Marshal() (dAtA []byte, err error) { @@ -239,48 +184,6 @@ func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } -func (m *FileUpload) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *FileUpload) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *FileUpload) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.FileInfo != nil { - { - size, err := m.FileInfo.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintSds(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x12 - } - if len(m.FileHash) > 0 { - i -= len(m.FileHash) - copy(dAtA[i:], m.FileHash) - i = encodeVarintSds(dAtA, i, uint64(len(m.FileHash))) - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - func (m *FileInfo) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) @@ -308,25 +211,23 @@ func (m *FileInfo) MarshalToSizedBuffer(dAtA []byte) (int, error) { i-- dAtA[i] = 0x1a } - if len(m.Reporter) > 0 { - i -= len(m.Reporter) - copy(dAtA[i:], m.Reporter) - i = encodeVarintSds(dAtA, i, uint64(len(m.Reporter))) + if len(m.Reporters) > 0 { + i -= len(m.Reporters) + copy(dAtA[i:], m.Reporters) + i = encodeVarintSds(dAtA, i, uint64(len(m.Reporters))) i-- dAtA[i] = 0x12 } - if m.Height != nil { - { - size := m.Height.Size() - i -= size - if _, err := m.Height.MarshalTo(dAtA[i:]); err != nil { - return 0, err - } - i = encodeVarintSds(dAtA, i, uint64(size)) + { + size := m.Height.Size() + i -= size + if _, err := m.Height.MarshalTo(dAtA[i:]); err != nil { + return 0, err } - i-- - dAtA[i] = 0xa + i = encodeVarintSds(dAtA, i, uint64(size)) } + i-- + dAtA[i] = 0xa return len(dAtA) - i, nil } @@ -354,34 +255,15 @@ func (m *Params) Size() (n int) { return n } -func (m *FileUpload) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.FileHash) - if l > 0 { - n += 1 + l + sovSds(uint64(l)) - } - if m.FileInfo != nil { - l = m.FileInfo.Size() - n += 1 + l + sovSds(uint64(l)) - } - return n -} - func (m *FileInfo) Size() (n int) { if m == nil { return 0 } var l int _ = l - if m.Height != nil { - l = m.Height.Size() - n += 1 + l + sovSds(uint64(l)) - } - l = len(m.Reporter) + l = m.Height.Size() + n += 1 + l + sovSds(uint64(l)) + l = len(m.Reporters) if l > 0 { n += 1 + l + sovSds(uint64(l)) } @@ -480,124 +362,6 @@ func (m *Params) Unmarshal(dAtA []byte) error { } return nil } -func (m *FileUpload) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowSds - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: FileUpload: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: FileUpload: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field FileHash", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowSds - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthSds - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthSds - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.FileHash = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field FileInfo", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowSds - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthSds - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthSds - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.FileInfo == nil { - m.FileInfo = &FileInfo{} - } - if err := m.FileInfo.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipSds(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthSds - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} func (m *FileInfo) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 @@ -657,17 +421,15 @@ func (m *FileInfo) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - var v github_com_cosmos_cosmos_sdk_types.Int - m.Height = &v if err := m.Height.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex case 2: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Reporter", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Reporters", wireType) } - var stringLen uint64 + var byteLen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowSds @@ -677,23 +439,25 @@ func (m *FileInfo) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - stringLen |= uint64(b&0x7F) << shift + byteLen |= int(b&0x7F) << shift if b < 0x80 { break } } - intStringLen := int(stringLen) - if intStringLen < 0 { + if byteLen < 0 { return ErrInvalidLengthSds } - postIndex := iNdEx + intStringLen + postIndex := iNdEx + byteLen if postIndex < 0 { return ErrInvalidLengthSds } if postIndex > l { return io.ErrUnexpectedEOF } - m.Reporter = string(dAtA[iNdEx:postIndex]) + m.Reporters = append(m.Reporters[:0], dAtA[iNdEx:postIndex]...) + if m.Reporters == nil { + m.Reporters = []byte{} + } iNdEx = postIndex case 3: if wireType != 2 { diff --git a/x/sds/types/types.go b/x/sds/types/types.go new file mode 100644 index 00000000..07f17a49 --- /dev/null +++ b/x/sds/types/types.go @@ -0,0 +1,14 @@ +package types + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" +) + +// NewFileInfo constructor +func NewFileInfo(height sdk.Int, reporters []byte, uploader string) FileInfo { + return FileInfo{ + Height: height, + Reporters: reporters, + Uploader: uploader, + } +} diff --git a/x/sds/types/uploaded_file.go b/x/sds/types/uploaded_file.go deleted file mode 100644 index e89fee26..00000000 --- a/x/sds/types/uploaded_file.go +++ /dev/null @@ -1,35 +0,0 @@ -package types - -import ( - "github.com/cosmos/cosmos-sdk/codec" - sdk "github.com/cosmos/cosmos-sdk/types" -) - -// NewFileInfo constructor -func NewFileInfo(height *sdk.Int, reporter, uploader string) FileInfo { - return FileInfo{ - Height: height, - Reporter: reporter, - Uploader: uploader, - } -} - -// MustMarshalFileInfo returns the fileInfo's bytes. Panics if fails -func MustMarshalFileInfo(cdc codec.Codec, file FileInfo) []byte { - return cdc.MustMarshal(&file) -} - -// MustUnmarshalFileInfo unmarshal a file's info from a store value. Panics if fails -func MustUnmarshalFileInfo(cdc codec.Codec, value []byte) FileInfo { - file, err := UnmarshalFileInfo(cdc, value) - if err != nil { - panic(err) - } - return file -} - -// UnmarshalFileInfo unmarshal a file's info from a store value -func UnmarshalFileInfo(cdc codec.Codec, value []byte) (fi FileInfo, err error) { - err = cdc.Unmarshal(value, &fi) - return fi, err -}