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

Track colony versions in the database #4

Merged
merged 7 commits into from
Jan 18, 2023

Conversation

jakubcolony
Copy link
Collaborator

@jakubcolony jakubcolony commented Jan 10, 2023

Description

This PR adds two concepts of tracking colony version:

  1. Tracking the highest colony version available in the network
  2. Tracking the current versions of individual colonies

To achieve 1), we listen to the ColonyVersionAdded event and utilise the existing CurrentVersion model already used for tracking highest available extension versions:

type CurrentVersion @model {
  id: ID!
  key: String! @index(name: "byKey", queryField: "getCurrentVersionByKey")
  version: Int!
}

For extensions, key represents the extension hash, in case of colonies, since there's only one type to track, key is set to colony string.

Additionally, we write the current highest version to the db on ingestor startup.

For 2), there is a new version field on Colony model that gets updated on ColonyUpgraded event. In the corresponding CDapp PR, you'll see the field added to the schema as well as colony creation mutation modified to include it.

Testing

Common steps

  1. (CDapp directory) Run git checkout feat/102-track-colony-version
  2. (CDapp) Apply the following patch:
diff --git a/docker/colony-cdapp-dev-env-orchestration.yaml b/docker/colony-cdapp-dev-env-orchestration.yaml
index 6e2a133..f319cc6 100644
--- a/docker/colony-cdapp-dev-env-orchestration.yaml
+++ b/docker/colony-cdapp-dev-env-orchestration.yaml
@@ -28,19 +28,19 @@ services:
     links:
     - "network-contracts:network-contracts.docker"
 
-  block-ingestor:
-    container_name: 'ingestor'
-    image: colony-cdapp-dev-env/block-ingestor:latest
-    volumes:
-      - '../amplify/mock-data:/colonyCDapp/amplify/mock-data'
-    ports:
-      - '10001:10001'
-    depends_on:
-      network-contracts:
-        condition: service_healthy
-    links:
-      - "network-contracts:network-contracts.docker"
-      - "amplify:amplify.docker"
+  # block-ingestor:
+  #   container_name: 'ingestor'
+  #   image: colony-cdapp-dev-env/block-ingestor:latest
+  #   volumes:
+  #     - '../amplify/mock-data:/colonyCDapp/amplify/mock-data'
+  #   ports:
+  #     - '10001:10001'
+  #   depends_on:
+  #     network-contracts:
+  #       condition: service_healthy
+  #   links:
+  #     - "network-contracts:network-contracts.docker"
+  #     - "amplify:amplify.docker"
 
   amplify:
     container_name: 'amplify'

  1. (CDapp) Run npm run dev.
  2. (block-ingestor directory) Run npm run dev.
  3. (CDapp) Run node scripts/temp-create-data.js

Storing the current colony version on ingestor start

  1. Run listCurrentVersions query, e.g.:
query ListCurrentVersions {
  listCurrentVersions {
    items {
      key
      version
    }
  }
}

You should see an entry with key colony and version set to 10.

Storing the colony version when new version is added to network

  1. (CDapp) Run npm run truffle console and paste the following code line-by-line:
// local dev ether router address
n = await IColonyNetwork.at('0x5CC4a96B08e8C88f2c6FC5772496FeD9666e4D1F')
// metacolony address
ma = await n.getMetaColony()
// metacolony instance
m = await IMetaColony.at(ma)
// get current version (10) resolver address
r = await n.getColonyVersionResolver(10)
// add new colony version (11) with previous version's resolver:
m.addNetworkColonyVersion(11, r)

You should see some logs in block-ingestor confirming it has picked up the event and if you run the listCurrentVersions query again, you should see the colony version updated.

Tracking the individual colony version when colony is upgraded

  1. Run the listCurrentVersions query. You should see an entry with key 0x3a157280ca91bB49dAe3D1619C55Da7F9D4438c3 which is the address of the first dev colony (and the one we will be upgrading in the next step). Its version should be 10.
  2. (CDapp) Run npm run truffle console, paste the code from the previous steps and add the following:
// first local dev colony
c = await IColony.at('0x3a157280ca91bB49dAe3D1619C55Da7F9D4438c3')
// upgrade colony to version 11
c.upgrade(11)

Again, you should see some logs in block-ingestor console. Run listCurrentVersions again to verify that the colony version has been updated in the database.

@jakubcolony jakubcolony self-assigned this Jan 10, 2023
@jakubcolony jakubcolony marked this pull request as ready for review January 11, 2023 15:43
@jakubcolony jakubcolony requested a review from a team January 11, 2023 15:43
Copy link
Contributor

@willm30 willm30 left a comment

Choose a reason for hiding this comment

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

LGTM 👍


await mutate('setCurrentVersion', {
input: {
key: 'colony',
Copy link
Contributor

Choose a reason for hiding this comment

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

Only suggestion would be moving this to a constant e.g COLONY_VERSION_KEY and referencing key: COLONY_VERSION_KEY

@jakubcolony
Copy link
Collaborator Author

Note: This has to be merged after JoinColony/colonyCDapp#163

Copy link
Member

@rdig rdig left a comment

Choose a reason for hiding this comment

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

Vert nice work yet again. I've left a comment but it's not something that needs to be done now.

* Function writing the highest colony version currently available in the network to the database
* Subsequent changes to available version are handled in eventProcessor
*/
const writeCurrentNetworkColonyVersion = async (): Promise<void> => {
Copy link
Member

Choose a reason for hiding this comment

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

I think it will be useful to write the latest version for colonies (and extensions) to the stats file as well.

This will help with checks once we get in production.

However, this will add some complexity, as you'll also need to add the logic of fetching the latest version when the ingestor starts initially.

In a effort to cut down on dev time, so we can actually make the end of february relese, I think we need to skip this for now

(but maybe create a issue for this so we can add it in at a later date)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Opened #9

@jakubcolony jakubcolony merged commit bf70f8f into port/extensions Jan 18, 2023
@jakubcolony jakubcolony deleted the feat/track-colony-version branch January 18, 2023 19:48
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.

None yet

3 participants