Skip to content

Commit

Permalink
fixed genesis
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMarstonConnell committed Aug 3, 2023
1 parent 3493557 commit 0960b55
Show file tree
Hide file tree
Showing 5 changed files with 258 additions and 45 deletions.
4 changes: 4 additions & 0 deletions proto/canine_chain/storage/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ message GenesisState {
repeated FidCid fid_cid_list = 5 [ (gogoproto.nullable) = false ];
repeated StoragePaymentInfo payment_info_list = 7 [ (gogoproto.nullable) = false ];
repeated Collateral collateral_list = 8 [ (gogoproto.nullable) = false ];
repeated ActiveProviders active_providers_list = 9 [ (gogoproto.nullable) = false ];
repeated ReportForm report_forms = 10 [ (gogoproto.nullable) = false ];
repeated AttestationForm attest_forms = 11 [ (gogoproto.nullable) = false ];


// this line is used by starport scaffolding # genesis/proto/state
}
20 changes: 20 additions & 0 deletions x/storage/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,22 @@ func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState)
for _, elem := range genState.CollateralList {
k.SetCollateral(ctx, elem)
}

// Set all the attestations
for _, elem := range genState.AttestForms {
k.SetAttestationForm(ctx, elem)
}

// Set all the reports
for _, elem := range genState.ReportForms {
k.SetReportForm(ctx, elem)
}

// Set all the active providers
for _, elem := range genState.ActiveProvidersList {
k.SetActiveProviders(ctx, elem)
}

// this line is used by starport scaffolding # genesis/module/init
k.SetParams(ctx, genState.Params)
}
Expand All @@ -56,6 +72,10 @@ func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState {
genesis.FidCidList = k.GetAllFidCid(ctx)
genesis.PaymentInfoList = k.GetAllStoragePaymentInfo(ctx)
genesis.CollateralList = k.GetAllCollateral(ctx)
genesis.ActiveProvidersList = k.GetAllActiveProviders(ctx)
genesis.ReportForms = k.GetAllReport(ctx)
genesis.AttestForms = k.GetAllAttestation(ctx)

// this line is used by starport scaffolding # genesis/module/export

return genesis
Expand Down
6 changes: 1 addition & 5 deletions x/storage/keeper/msg_server_report.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ package keeper
import (
"context"

sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/tendermint/tendermint/libs/rand"

sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/jackalLabs/canine-chain/v3/x/storage/types"
)

Expand Down Expand Up @@ -88,8 +86,6 @@ func (k Keeper) RequestReport(ctx sdk.Context, cid string) ([]string, error) {
return nil, sdkerrors.Wrapf(types.ErrInvalidLengthQuery, "not enough providers online")
}

rand.Seed(ctx.BlockHeight())

attestations := make([]*types.Attestation, params.AttestFormSize)

providerAddresses := make([]string, params.AttestFormSize)
Expand Down
8 changes: 5 additions & 3 deletions x/storage/keeper/providers.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,13 @@ func (k Keeper) GetActiveProviders(ctx sdk.Context, filterAddress string) []type

i64Size := int64(size)

rand.Seed(ctx.BlockHeight())
r := rand.NewRand() // creating a new random generator to ensure no interference

r.Seed(ctx.BlockHeight())

for i := 0; i < rounds; i++ {
x := rand.Int63n(i64Size)
y := rand.Int63n(i64Size)
x := r.Int63n(i64Size)
y := r.Int63n(i64Size)

providers[x], providers[y] = providers[y], providers[x]
}
Expand Down
265 changes: 228 additions & 37 deletions x/storage/types/genesis.pb.go

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

0 comments on commit 0960b55

Please sign in to comment.