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

feat(app): add upgrade handlers #1121

Merged
merged 33 commits into from
Jun 3, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
adccebe
feat: wip mainnet upgrade handler
aleem1314 May 23, 2022
cd62000
wip: add ecocredit state migrations
aleem1314 May 24, 2022
5186804
implement recover funds from lost account
aleem1314 May 25, 2022
fd24f1b
chore: fix tests
aleem1314 May 25, 2022
94f830d
chore: add test
aleem1314 May 25, 2022
82bc8cc
chore: fix test
aleem1314 May 25, 2022
0e33ef0
Update app/stable_appconfig.go
aleem1314 May 25, 2022
0dc37be
chore: cleanup
aleem1314 May 25, 2022
4eaff10
chore: cleanup
aleem1314 May 25, 2022
02fedd8
feat: add redwood migrations
aleem1314 May 26, 2022
ccfa0f8
Update x/ecocredit/migrations/v3/patch.go
aleem1314 May 26, 2022
70b58e8
feat: add redwood migration tests
aleem1314 May 27, 2022
8efe829
Merge branch 'aleem/980-upgrade-handlers' of https://github.com/regen…
aleem1314 May 27, 2022
6747aa6
chore: revert core_test.go
aleem1314 May 27, 2022
11dfd85
Update app/stable_appconfig.go
aleem1314 May 27, 2022
0004544
Merge branch 'aleem/980-upgrade-handlers' of https://github.com/regen…
aleem1314 May 27, 2022
9ed5b5b
chore: review changes
aleem1314 May 27, 2022
765fb4f
chore: add redwood upgrade handler
aleem1314 May 27, 2022
61aceda
Update app/stable_appconfig.go
aleem1314 May 28, 2022
571c3b8
Update app/stable_appconfig.go
aleem1314 May 28, 2022
44ef5b7
Merge branch 'master' into aleem/980-upgrade-handlers
anilcse Jun 2, 2022
9dd7f37
Merge branch 'master' into aleem/980-upgrade-handlers
ryanchristo Jun 2, 2022
02af4e4
Update x/ecocredit/migrations/v3/patch_test.go
aleem1314 Jun 3, 2022
0f4aaa5
Update x/ecocredit/migrations/v3/patch_test.go
aleem1314 Jun 3, 2022
343af4a
Update x/ecocredit/migrations/v3/patch_test.go
aleem1314 Jun 3, 2022
50d012b
Update x/ecocredit/migrations/v3/patch_test.go
aleem1314 Jun 3, 2022
7ecc794
chore: review changes
aleem1314 Jun 3, 2022
168face
Merge branch 'aleem/980-upgrade-handlers' of https://github.com/regen…
aleem1314 Jun 3, 2022
372f378
Merge branch 'master' into aleem/980-upgrade-handlers
aleem1314 Jun 3, 2022
d6bc0f2
chore: fix errors
aleem1314 Jun 3, 2022
2e0def5
Update x/ecocredit/migrations/v3/patch.go
ryanchristo Jun 3, 2022
9982038
update reference id comments and checks
ryanchristo Jun 3, 2022
fe9dfaf
Merge branch 'master' into aleem/980-upgrade-handlers
ryanchristo Jun 3, 2022
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
Prev Previous commit
Next Next commit
feat: add redwood migration tests
  • Loading branch information
aleem1314 committed May 27, 2022
commit 70b58e80fe2163c92d487ebb9fae14097ac519b8
2 changes: 1 addition & 1 deletion x/ecocredit/migrations/v3/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ func MigrateState(sdkCtx sdk.Context, storeKey storetypes.StoreKey,
projectId = id
}

startDate, endDate, err := parseBatchDenom(batchInfo.BatchDenom)
startDate, endDate, err := ParseBatchDenom(batchInfo.BatchDenom)
if err != nil {
return err
}
Expand Down
1 change: 0 additions & 1 deletion x/ecocredit/migrations/v3/core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ func TestMigrations(t *testing.T) {
assert.NilError(t, cms.LoadLatestVersion())
ormCtx := ormtable.WrapContextDefault(ormtest.NewMemoryBackend())
sdkCtx := sdk.NewContext(cms, tmproto.Header{}, false, log.NewNopLogger()).WithContext(ormCtx)
sdkCtx = sdkCtx.WithChainID("regen-1")

store := sdkCtx.KVStore(ecocreditKey)

Expand Down
2 changes: 1 addition & 1 deletion x/ecocredit/migrations/v3/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func IterateSupplies(store sdk.KVStore, storeKey byte, cb func(denom, supply str
return nil
}

func parseBatchDenom(denom string) (*time.Time, *time.Time, error) {
func ParseBatchDenom(denom string) (*time.Time, *time.Time, error) {
// batch denom format: <class id>-<start date>-<end date>-<batch seq no>
result := strings.Split(denom, "-")
if len(result) != 4 {
Expand Down
2 changes: 1 addition & 1 deletion x/ecocredit/migrations/v3/keys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func TestParseBatchDenom(t *testing.T) {

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
sd, ed, err := parseBatchDenom(tc.denom)
sd, ed, err := ParseBatchDenom(tc.denom)
if tc.expErr {
require.Error(t, err)
require.Contains(t, err.Error(), tc.errMessage)
Expand Down
75 changes: 37 additions & 38 deletions x/ecocredit/migrations/v3/patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package v3

import (
"context"
"fmt"
"time"

sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -21,9 +20,44 @@ func patchMigrate(ctx context.Context, sdkCtx sdk.Context, ss api.StateStore,
return patchMainnet(ctx, ss, oldBatchDenomToNewDenomMap)
} else if sdkCtx.ChainID() == "regen-redwood-1" {
return patchRedwood(ctx, ss, basketStore, oldBatchDenomToNewDenomMap)
} else {
return fmt.Errorf("invalid chain-id %s", sdkCtx.ChainID())
}

return nil
}

func patchMainnet(ctx context.Context, ss api.StateStore, oldBatchDenomToNewDenomMap map[string]string) error {
// project location -> reference-id
// CD-MN -> "" // TODO: add reference-id
// KE -> ""
ryanchristo marked this conversation as resolved.
Show resolved Hide resolved

locationToReferenceIdMap := make(map[string]string)
locationToReferenceIdMap["CD-MN"] = ""
locationToReferenceIdMap["KE"] = ""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
locationToReferenceIdMap["CD-MN"] = ""
locationToReferenceIdMap["KE"] = ""
locationToReferenceIdMap["CD-MN"] = "VCS-934"
locationToReferenceIdMap["KE"] = "VCS-612"

@S4mmyb what do you think of this for the mai ndombw and kasigao reference ID's?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Committing this change and merging this pull request so that we can tag a beta and test. If we need to make any revisions, we can do so at a later point in time. Updated the issue and added followups: #980


// add reference id to existing projects
if err := addReferenceIds(ctx, ss, locationToReferenceIdMap); err != nil {
return err
}

// batch issuance dates
// C01-20190101-20191231-001 - "2022-05-06T01:33:13Z"
// C01-20190101-20191231-002 - "2022-05-06T01:33:19Z"
// C01-20190101-20191231-003 - "2022-05-06T01:33:25Z"
// C01-20190101-20191231-004 - "2022-05-06T01:33:31Z"

batchIdToIssuanceDateMap := make(map[string]string)
batchIdToIssuanceDateMap["C01-20190101-20191231-001"] = "2022-05-06T01:33:13Z"
batchIdToIssuanceDateMap["C01-20190101-20191231-002"] = "2022-05-06T01:33:19Z"
batchIdToIssuanceDateMap["C01-20190101-20191231-003"] = "2022-05-06T01:33:25Z"
batchIdToIssuanceDateMap["C01-20190101-20191231-004"] = "2022-05-06T01:33:31Z"
// update issuance date for credit batches
if err := updateBatchIssueanceDate(ctx, ss, oldBatchDenomToNewDenomMap, batchIdToIssuanceDateMap); err != nil {
return err
}

// we don't have baskets on mainnet

return nil
}

func patchRedwood(ctx context.Context, ss api.StateStore,
Expand Down Expand Up @@ -109,41 +143,6 @@ func updateBasketCurator(ctx context.Context, ss api.StateStore, basketStore bas
return nil
}

func patchMainnet(ctx context.Context, ss api.StateStore, oldBatchDenomToNewDenomMap map[string]string) error {
// project location -> reference-id
// CD-MN -> "" // TODO: add reference-id
// KE -> ""

locationToReferenceIdMap := make(map[string]string)
locationToReferenceIdMap["CD-MN"] = ""
locationToReferenceIdMap["KE"] = ""

// add reference id to existing projects
if err := addReferenceIds(ctx, ss, locationToReferenceIdMap); err != nil {
return err
}

// batch issuance dates
// C01-20190101-20191231-001 - "2022-05-06T01:33:13Z"
// C01-20190101-20191231-002 - "2022-05-06T01:33:19Z"
// C01-20190101-20191231-003 - "2022-05-06T01:33:25Z"
// C01-20190101-20191231-004 - "2022-05-06T01:33:31Z"

batchIdToIssuanceDateMap := make(map[string]string)
batchIdToIssuanceDateMap["C01-20190101-20191231-001"] = "2022-05-06T01:33:13Z"
batchIdToIssuanceDateMap["C01-20190101-20191231-002"] = "2022-05-06T01:33:19Z"
batchIdToIssuanceDateMap["C01-20190101-20191231-003"] = "2022-05-06T01:33:25Z"
batchIdToIssuanceDateMap["C01-20190101-20191231-004"] = "2022-05-06T01:33:31Z"
// update issuance date for credit batches
if err := updateBatchIssueanceDate(ctx, ss, oldBatchDenomToNewDenomMap, batchIdToIssuanceDateMap); err != nil {
return err
}

// we don't have baskets on mainnet

return nil
}

func addReferenceIds(ctx context.Context, ss api.StateStore, locationToReferenceIdMap map[string]string) error {
itr, err := ss.ProjectTable().List(ctx, api.ProjectKeyIndexKey{})
if err != nil {
Expand Down
Loading