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

Change genesis preserving contract history #1076

Conversation

GNaD13
Copy link
Contributor

@GNaD13 GNaD13 commented Nov 4, 2022

Close #878

@GNaD13 GNaD13 requested a review from alpe as a code owner November 4, 2022 13:25
@codecov
Copy link

codecov bot commented Nov 4, 2022

Codecov Report

Merging #1076 (a1b63bf) into main (a9ce273) will increase coverage by 0.15%.
The diff coverage is 91.11%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1076      +/-   ##
==========================================
+ Coverage   59.27%   59.42%   +0.15%     
==========================================
  Files          53       53              
  Lines        6758     6783      +25     
==========================================
+ Hits         4006     4031      +25     
+ Misses       2456     2454       -2     
- Partials      296      298       +2     
Impacted Files Coverage Δ
x/wasm/keeper/querier.go 72.19% <ø> (-0.13%) ⬇️
x/wasm/types/genesis.go 87.87% <42.85%> (-5.57%) ⬇️
x/wasm/keeper/genesis.go 89.47% <100.00%> (+0.14%) ⬆️
x/wasm/keeper/keeper.go 87.40% <100.00%> (-0.02%) ⬇️
x/wasm/types/test_fixtures.go 95.04% <100.00%> (-0.58%) ⬇️
x/wasm/types/types.go 64.53% <100.00%> (+4.32%) ⬆️

@alpe alpe changed the title change genesis preserving contract history Change genesis preserving contract history Nov 4, 2022
Copy link
Contributor

@alpe alpe left a comment

Choose a reason for hiding this comment

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

Very nice work! Thanks a lot for the changes 👍

You addressed the created date proper. Unfortunately this was only half of the original story. The other part is about the ContractHistory. The history contains all the code changes for a contract. We don't export it but create a new start on import .
if you can add this to this PR, then #878 would be resolved. But also happy to merge this one and have a second to finish the issue. What you prefer.

@@ -107,8 +107,6 @@ func ExportGenesis(ctx sdk.Context, keeper *Keeper) *types.GenesisState {
state = append(state, types.Model{Key: key, Value: value})
return false
})
// redact contract info
contract.Created = nil
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@@ -211,22 +212,6 @@ func TestAppImportExport(t *testing.T) {
dropContractHistory(ctxA.KVStore(app.keys[wasm.StoreKey]), prefixes...)
dropContractHistory(ctxB.KVStore(newApp.keys[wasm.StoreKey]), prefixes...)

normalizeContractInfo := func(ctx sdk.Context, app *WasmApp) {
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@GNaD13
Copy link
Contributor Author

GNaD13 commented Nov 4, 2022

Very nice work! Thanks a lot for the changes +1

You addressed the created date proper. Unfortunately this was only half of the original story. The other part is about the ContractHistory. The history contains all the code changes for a contract. We don't export it but create a new start on import . if you can add this to this PR, then #878 would be resolved. But also happy to merge this one and have a second to finish the issue. What you prefer.

Got it, I will continue with the Contract History. Tysm :3

@GNaD13 GNaD13 marked this pull request as draft November 6, 2022 05:54
@GNaD13 GNaD13 marked this pull request as ready for review November 6, 2022 15:27
@GNaD13 GNaD13 requested a review from alpe November 6, 2022 16:34
Copy link
Contributor

@alpe alpe left a comment

Choose a reason for hiding this comment

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

This looks almost perfect now. Thanks a lot for your updates!
I have added some minor notes now but I need to do a deeper review tomorrow.

@@ -53,6 +53,7 @@ message Contract {
string contract_address = 1;
ContractInfo contract_info = 2 [ (gogoproto.nullable) = false ];
repeated Model contract_state = 3 [ (gogoproto.nullable) = false ];
repeated ContractCodeHistoryEntry contract_code_history = 4 [ (gogoproto.nullable) = false ];
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

k.addToContractCodeSecondaryIndex(ctx, contractAddr, historyEntry)
k.addToContractCreatorSecondaryIndex(ctx, creatorAddress, historyEntry.Updated, contractAddr)
k.addToContractCodeSecondaryIndex(ctx, contractAddr, entries[len(entries)-1])
k.addToContractCreatorSecondaryIndex(ctx, creatorAddress, entries[0].Updated, contractAddr)
Copy link
Contributor

Choose a reason for hiding this comment

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

Very nice to use the history data to feed the indexes with proper dates! 👍

io "io"
math "math"
math_bits "math/bits"

Copy link
Contributor

Choose a reason for hiding this comment

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

Please run make proto-all instead that includes the code formatters

@@ -41,7 +41,7 @@ func InitGenesis(ctx sdk.Context, keeper *Keeper, data types.GenesisState, staki
if err != nil {
return nil, sdkerrors.Wrapf(err, "address in contract number %d", i)
}
err = keeper.importContract(ctx, contractAddr, &contract.ContractInfo, contract.ContractState)
err = keeper.importContract(ctx, contractAddr, &contract.ContractInfo, contract.ContractState, contract.ContractCodeHistory)
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add some sanity checks for ContractCodeHistory to the ValidateBacis()

@GNaD13
Copy link
Contributor Author

GNaD13 commented Nov 9, 2022

This looks almost perfect now. Thanks a lot for your updates! I have added some minor notes now but I need to do a deeper review tomorrow.

Thank youuuuuuuuuuu sir :3

Copy link
Contributor

@alpe alpe left a comment

Choose a reason for hiding this comment

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

Wonderful! 🌻
Thanks a lot for taking this task and the PR! Very well done! 🥇

I did some manual tests with state export/ import to confirm it is working as expected and it does. Only the wasmd q wasm contract-history query does not return update data but I will provide a fix when this is merged to main.

@alpe alpe merged commit 4c6afb3 into CosmWasm:main Nov 11, 2022
pinosu added a commit that referenced this pull request Nov 11, 2022
* Add StoreAndInstantiateContract gov proposal

* Add integration tests

* Bump github.com/prometheus/client_golang from 1.13.0 to 1.14.0

Bumps [github.com/prometheus/client_golang](https://github.com/prometheus/client_golang) from 1.13.0 to 1.14.0.
- [Release notes](https://github.com/prometheus/client_golang/releases)
- [Changelog](https://github.com/prometheus/client_golang/blob/main/CHANGELOG.md)
- [Commits](prometheus/client_golang@v1.13.0...v1.14.0)

---
updated-dependencies:
- dependency-name: github.com/prometheus/client_golang
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

* Remove exposed functions

* Add tests

* Add Developer's guide and best practices (#1075)

* Add Developer's guide and best practices

* Fix comments

* Change genesis preserving contract history (#1076)

* preserve contract created date on genesis import and add query contract created date

* add validate created

* fix sims test app import export

* add preserve contract history

* Make proto-all only

* Remove ResetFromGenesis

* Add validation

Co-authored-by: Alex Peters <[email protected]>

* Return contract history updates

* Bump github.com/spf13/viper from 1.13.0 to 1.14.0 (#1082)

Bumps [github.com/spf13/viper](https://github.com/spf13/viper) from 1.13.0 to 1.14.0.
- [Release notes](https://github.com/spf13/viper/releases)
- [Commits](spf13/viper@v1.13.0...v1.14.0)

---
updated-dependencies:
- dependency-name: github.com/spf13/viper
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Revert "Bump github.com/spf13/viper from 1.13.0 to 1.14.0 (#1082)"

This reverts commit cf81eb8.

* Add cli and refactor code

* Contract authz - redesign (#1077)

* Add contract authz proto

* Implement contract autorization

* Register contract authz

* Add contract-authz tests

* Consume gas for contract authz

* Add contract authz cli

* Update cli usage

* Model spike

* Add max funds limit

* Redesign authz model

* Start e2e test

* Full e2e test

* Test filter and limits

* Test accept

* Fix description

* No linter warning

Co-authored-by: Giancarlos Salas <[email protected]>

* Add StoreAndInstantiateContract gov proposal

* Add integration tests

* Remove exposed functions

* Add tests

* Add cli and refactor code

* Fix comments

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: GNaD13 <[email protected]>
Co-authored-by: Alex Peters <[email protected]>
Co-authored-by: Giancarlos Salas <[email protected]>
NoahSaso pushed a commit to NoahSaso/wasmd that referenced this pull request Dec 2, 2022
* preserve contract created date on genesis import and add query contract created date

* add validate created

* fix sims test app import export

* add preserve contract history

* Make proto-all only

* Remove ResetFromGenesis

* Add validation

Co-authored-by: Alex Peters <[email protected]>
NoahSaso pushed a commit to NoahSaso/wasmd that referenced this pull request Dec 2, 2022
* Add StoreAndInstantiateContract gov proposal

* Add integration tests

* Bump github.com/prometheus/client_golang from 1.13.0 to 1.14.0

Bumps [github.com/prometheus/client_golang](https://github.com/prometheus/client_golang) from 1.13.0 to 1.14.0.
- [Release notes](https://github.com/prometheus/client_golang/releases)
- [Changelog](https://github.com/prometheus/client_golang/blob/main/CHANGELOG.md)
- [Commits](prometheus/client_golang@v1.13.0...v1.14.0)

---
updated-dependencies:
- dependency-name: github.com/prometheus/client_golang
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

* Remove exposed functions

* Add tests

* Add Developer's guide and best practices (CosmWasm#1075)

* Add Developer's guide and best practices

* Fix comments

* Change genesis preserving contract history (CosmWasm#1076)

* preserve contract created date on genesis import and add query contract created date

* add validate created

* fix sims test app import export

* add preserve contract history

* Make proto-all only

* Remove ResetFromGenesis

* Add validation

Co-authored-by: Alex Peters <[email protected]>

* Return contract history updates

* Bump github.com/spf13/viper from 1.13.0 to 1.14.0 (CosmWasm#1082)

Bumps [github.com/spf13/viper](https://github.com/spf13/viper) from 1.13.0 to 1.14.0.
- [Release notes](https://github.com/spf13/viper/releases)
- [Commits](spf13/viper@v1.13.0...v1.14.0)

---
updated-dependencies:
- dependency-name: github.com/spf13/viper
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Revert "Bump github.com/spf13/viper from 1.13.0 to 1.14.0 (CosmWasm#1082)"

This reverts commit cf81eb8.

* Add cli and refactor code

* Contract authz - redesign (CosmWasm#1077)

* Add contract authz proto

* Implement contract autorization

* Register contract authz

* Add contract-authz tests

* Consume gas for contract authz

* Add contract authz cli

* Update cli usage

* Model spike

* Add max funds limit

* Redesign authz model

* Start e2e test

* Full e2e test

* Test filter and limits

* Test accept

* Fix description

* No linter warning

Co-authored-by: Giancarlos Salas <[email protected]>

* Add StoreAndInstantiateContract gov proposal

* Add integration tests

* Remove exposed functions

* Add tests

* Add cli and refactor code

* Fix comments

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: GNaD13 <[email protected]>
Co-authored-by: Alex Peters <[email protected]>
Co-authored-by: Giancarlos Salas <[email protected]>
Magicloud pushed a commit to fpco/wasmd that referenced this pull request Jan 13, 2023
* preserve contract created date on genesis import and add query contract created date

* add validate created

* fix sims test app import export

* add preserve contract history

* Make proto-all only

* Remove ResetFromGenesis

* Add validation

Co-authored-by: Alex Peters <[email protected]>
Magicloud pushed a commit to fpco/wasmd that referenced this pull request Jan 13, 2023
* Add StoreAndInstantiateContract gov proposal

* Add integration tests

* Bump github.com/prometheus/client_golang from 1.13.0 to 1.14.0

Bumps [github.com/prometheus/client_golang](https://github.com/prometheus/client_golang) from 1.13.0 to 1.14.0.
- [Release notes](https://github.com/prometheus/client_golang/releases)
- [Changelog](https://github.com/prometheus/client_golang/blob/main/CHANGELOG.md)
- [Commits](prometheus/client_golang@v1.13.0...v1.14.0)

---
updated-dependencies:
- dependency-name: github.com/prometheus/client_golang
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

* Remove exposed functions

* Add tests

* Add Developer's guide and best practices (CosmWasm#1075)

* Add Developer's guide and best practices

* Fix comments

* Change genesis preserving contract history (CosmWasm#1076)

* preserve contract created date on genesis import and add query contract created date

* add validate created

* fix sims test app import export

* add preserve contract history

* Make proto-all only

* Remove ResetFromGenesis

* Add validation

Co-authored-by: Alex Peters <[email protected]>

* Return contract history updates

* Bump github.com/spf13/viper from 1.13.0 to 1.14.0 (CosmWasm#1082)

Bumps [github.com/spf13/viper](https://github.com/spf13/viper) from 1.13.0 to 1.14.0.
- [Release notes](https://github.com/spf13/viper/releases)
- [Commits](spf13/viper@v1.13.0...v1.14.0)

---
updated-dependencies:
- dependency-name: github.com/spf13/viper
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Revert "Bump github.com/spf13/viper from 1.13.0 to 1.14.0 (CosmWasm#1082)"

This reverts commit cf81eb8.

* Add cli and refactor code

* Contract authz - redesign (CosmWasm#1077)

* Add contract authz proto

* Implement contract autorization

* Register contract authz

* Add contract-authz tests

* Consume gas for contract authz

* Add contract authz cli

* Update cli usage

* Model spike

* Add max funds limit

* Redesign authz model

* Start e2e test

* Full e2e test

* Test filter and limits

* Test accept

* Fix description

* No linter warning

Co-authored-by: Giancarlos Salas <[email protected]>

* Add StoreAndInstantiateContract gov proposal

* Add integration tests

* Remove exposed functions

* Add tests

* Add cli and refactor code

* Fix comments

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: GNaD13 <[email protected]>
Co-authored-by: Alex Peters <[email protected]>
Co-authored-by: Giancarlos Salas <[email protected]>
conorpp pushed a commit to wormhole-foundation/wasmd that referenced this pull request Feb 1, 2023
* preserve contract created date on genesis import and add query contract created date

* add validate created

* fix sims test app import export

* add preserve contract history

* Make proto-all only

* Remove ResetFromGenesis

* Add validation

Co-authored-by: Alex Peters <[email protected]>
conorpp pushed a commit to wormhole-foundation/wasmd that referenced this pull request Feb 1, 2023
* Add StoreAndInstantiateContract gov proposal

* Add integration tests

* Bump github.com/prometheus/client_golang from 1.13.0 to 1.14.0

Bumps [github.com/prometheus/client_golang](https://github.com/prometheus/client_golang) from 1.13.0 to 1.14.0.
- [Release notes](https://github.com/prometheus/client_golang/releases)
- [Changelog](https://github.com/prometheus/client_golang/blob/main/CHANGELOG.md)
- [Commits](prometheus/client_golang@v1.13.0...v1.14.0)

---
updated-dependencies:
- dependency-name: github.com/prometheus/client_golang
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

* Remove exposed functions

* Add tests

* Add Developer's guide and best practices (CosmWasm#1075)

* Add Developer's guide and best practices

* Fix comments

* Change genesis preserving contract history (CosmWasm#1076)

* preserve contract created date on genesis import and add query contract created date

* add validate created

* fix sims test app import export

* add preserve contract history

* Make proto-all only

* Remove ResetFromGenesis

* Add validation

Co-authored-by: Alex Peters <[email protected]>

* Return contract history updates

* Bump github.com/spf13/viper from 1.13.0 to 1.14.0 (CosmWasm#1082)

Bumps [github.com/spf13/viper](https://github.com/spf13/viper) from 1.13.0 to 1.14.0.
- [Release notes](https://github.com/spf13/viper/releases)
- [Commits](spf13/viper@v1.13.0...v1.14.0)

---
updated-dependencies:
- dependency-name: github.com/spf13/viper
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Revert "Bump github.com/spf13/viper from 1.13.0 to 1.14.0 (CosmWasm#1082)"

This reverts commit cf81eb8.

* Add cli and refactor code

* Contract authz - redesign (CosmWasm#1077)

* Add contract authz proto

* Implement contract autorization

* Register contract authz

* Add contract-authz tests

* Consume gas for contract authz

* Add contract authz cli

* Update cli usage

* Model spike

* Add max funds limit

* Redesign authz model

* Start e2e test

* Full e2e test

* Test filter and limits

* Test accept

* Fix description

* No linter warning

Co-authored-by: Giancarlos Salas <[email protected]>

* Add StoreAndInstantiateContract gov proposal

* Add integration tests

* Remove exposed functions

* Add tests

* Add cli and refactor code

* Fix comments

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: GNaD13 <[email protected]>
Co-authored-by: Alex Peters <[email protected]>
Co-authored-by: Giancarlos Salas <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Preserve contract history/ created date on genesis import
2 participants