Skip to content

Commit

Permalink
Merge branch 'chains/cheqd/mainnet' of github.com:forbole/callisto in…
Browse files Browse the repository at this point in the history
…to chains/cheqd/testnet
  • Loading branch information
filipdjokic committed May 27, 2024
2 parents de4cfdd + 0c315d6 commit e1519fd
Show file tree
Hide file tree
Showing 22 changed files with 417 additions and 81 deletions.
60 changes: 60 additions & 0 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: docker-build

on:
push:
branches:
- cosmos/*/*
- chains/*/*

jobs:
docker:
runs-on: ubuntu-latest
steps:
- name: Checkout 🛎️
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set Callisto chain name 🔧
shell: bash
run: echo "CHAIN_NAME=$(echo ${GITHUB_REF#refs/heads/} | sed 's/\//_/g')" >> $GITHUB_ENV

- name: Set Callisto version 🔧
shell: bash
run: echo "GITHUB_VERSION=$(git describe --tags)" >> $GITHUB_ENV

- name: Prepare tags 🏷️
id: prep
run: |
DOCKER_IMAGE=${{ secrets.DOCKERHUB_BDJUNO_REPO }}
CHAIN_NAME="${{env.CHAIN_NAME}}"
VERSION="${{env.GITHUB_VERSION}}"
TAGS="${DOCKER_IMAGE}:${CHAIN_NAME}-${VERSION}"
echo ::set-output name=version::${VERSION}
echo ::set-output name=tags::${TAGS}
echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ')
- name: Determine Dockerfile to use 🔍
run: |
if [[ -f Dockerfile.cosmwasm ]]; then
export DOCKERFILE=Dockerfile.cosmwasm
else
export DOCKERFILE=Dockerfile.default
fi
echo "DOCKERFILE=${DOCKERFILE}" >> $GITHUB_ENV
- name: Set up Docker Buildx 🧰
uses: docker/setup-buildx-action@v3

- name: Login to DockerHub 👤
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Build and push 📤
uses: docker/build-push-action@v5
with:
context: .
file: "./${{ env.DOCKERFILE }}"
push: true
tags: ${{ steps.prep.outputs.tags }}
16 changes: 16 additions & 0 deletions .github/workflows/lint-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: "Lint PR"

on:
pull_request_target:
types:
- opened
- edited
- synchronize

jobs:
main:
runs-on: ubuntu-latest
steps:
- uses: amannn/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
52 changes: 52 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Tests
# Tests / Code Coverage workflow runs unit tests and uploads a code coverage report.
# This workflow is run on pushes to master & every Pull Requests where a .go, .mod, .sum have been changed.
on:
pull_request:
push:
branches:
- chains/*
- cosmos/*

jobs:
Cleanup-runs:
runs-on: ubuntu-latest
steps:
- uses: rokroskar/workflow-run-cleanup-action@master
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
if: "!startsWith(github.ref, 'refs/tags/') && !startsWith(github.ref, 'refs/tags/cosmos')"

Unit-tests:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout 🛎️
uses: actions/checkout@v4

- name: Setup Go 🧰
uses: actions/setup-go@v5
with:
go-version: "1.20"

- name: Compute diff 📜
uses: technote-space/[email protected]
id: git_diff
with:
SUFFIX_FILTER: |
.go
.mod
.sum
- name: Build 🔨
if: "env.GIT_DIFF != ''"
run: make build

- name: Test & Coverage report creation 🧪
run: make test-unit stop-docker-test

- name: Upload coverage 📤
if: "env.GIT_DIFF != ''"
uses: codecov/[email protected]
with:
file: ./coverage.txt
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ stop-docker-test:

start-docker-test: stop-docker-test
@echo "Starting Docker container..."
@docker run --name callisto-test-db -e POSTGRES_USER=callisto -e POSTGRES_PASSWORD=password -e POSTGRES_DB=callisto -d -p 6433:5432 postgres
@docker run --name callisto-test-db -e POSTGRES_USER=callisto -e POSTGRES_PASSWORD=password -e POSTGRES_DB=callisto -d -v ./database/schema:/docker-entrypoint-initdb.d -p 6433:5432 postgres
.PHONY: start-docker-test

test-unit: start-docker-test
Expand Down
2 changes: 2 additions & 0 deletions cmd/migrate/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

v3 "github.com/forbole/callisto/v4/cmd/migrate/v3"
v5 "github.com/forbole/callisto/v4/cmd/migrate/v5"
v6 "github.com/forbole/callisto/v4/cmd/migrate/v6"
)

type Migrator func(parseCfg *parsecmdtypes.Config) error
Expand All @@ -17,6 +18,7 @@ var (
migrations = map[string]Migrator{
"v3": v3.RunMigration,
"v5": v5.RunMigration,
"v6": v6.RunMigration,
}
)

Expand Down
43 changes: 43 additions & 0 deletions cmd/migrate/v6/migrate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package v6

import (
"fmt"

v6db "github.com/forbole/callisto/v4/database/migrate/v6"
parse "github.com/forbole/juno/v5/cmd/parse/types"
"github.com/forbole/juno/v5/database"
"github.com/forbole/juno/v5/database/postgresql"
"github.com/forbole/juno/v5/types/config"
)

// RunMigration runs the migrations to v5
func RunMigration(parseConfig *parse.Config) error {
cfg, err := GetConfig()
if err != nil {
return fmt.Errorf("error while reading config: %s", err)
}

// Migrate the database
err = migrateDb(cfg, parseConfig)
if err != nil {
return fmt.Errorf("error while migrating database: %s", err)
}

return nil
}

func migrateDb(cfg config.Config, parseConfig *parse.Config) error {
// Build the codec
encodingConfig := parseConfig.GetEncodingConfigBuilder()()

// Get the db
databaseCtx := database.NewContext(cfg.Database, encodingConfig, parseConfig.GetLogger())
db, err := postgresql.Builder(databaseCtx)
if err != nil {
return fmt.Errorf("error while building the db: %s", err)
}

// Build the migrator and perform the migrations
migrator := v6db.NewMigrator(db.(*postgresql.Database))
return migrator.Migrate()
}
29 changes: 29 additions & 0 deletions cmd/migrate/v6/utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package v6

import (
"fmt"
"os"
"path"

"github.com/forbole/juno/v5/types/config"
"gopkg.in/yaml.v3"
)

// GetConfig returns the configuration reading it from the config.yaml file present inside the home directory
func GetConfig() (config.Config, error) {
file := path.Join(config.HomePath, "config.yaml")

// Make sure the path exists
if _, err := os.Stat(file); os.IsNotExist(err) {
return config.Config{}, fmt.Errorf("config file does not exist")
}

bz, err := os.ReadFile(file)
if err != nil {
return config.Config{}, fmt.Errorf("error while reading config file: %s", err)
}

var cfg config.Config
err = yaml.Unmarshal(bz, &cfg)
return cfg, err
}
1 change: 1 addition & 0 deletions cmd/parse/gov/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ func NewGovCmd(parseConfig *parsecmdtypes.Config) *cobra.Command {

cmd.AddCommand(
proposalCmd(parseConfig),
paramsCmd(parseConfig),
)

return cmd
Expand Down
52 changes: 52 additions & 0 deletions cmd/parse/gov/params.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package gov

import (
"github.com/spf13/cobra"

"github.com/forbole/callisto/v4/database"
"github.com/forbole/callisto/v4/modules/distribution"
"github.com/forbole/callisto/v4/modules/gov"
"github.com/forbole/callisto/v4/modules/mint"
"github.com/forbole/callisto/v4/modules/slashing"
"github.com/forbole/callisto/v4/modules/staking"
modulestypes "github.com/forbole/callisto/v4/modules/types"
parsecmdtypes "github.com/forbole/juno/v5/cmd/parse/types"
"github.com/forbole/juno/v5/types/config"
)

func paramsCmd(parseConfig *parsecmdtypes.Config) *cobra.Command {
return &cobra.Command{
Use: "params",
Short: "Get the current parameters of the gov module",
RunE: func(cmd *cobra.Command, args []string) error {
parseCtx, err := parsecmdtypes.GetParserContext(config.Cfg, parseConfig)
if err != nil {
return err
}

sources, err := modulestypes.BuildSources(config.Cfg.Node, parseCtx.EncodingConfig)
if err != nil {
return err
}

// Get the database
db := database.Cast(parseCtx.Database)

// Build expected modules of gov modules
distrModule := distribution.NewModule(sources.DistrSource, parseCtx.EncodingConfig.Codec, db)
mintModule := mint.NewModule(sources.MintSource, parseCtx.EncodingConfig.Codec, db)
slashingModule := slashing.NewModule(sources.SlashingSource, parseCtx.EncodingConfig.Codec, db)
stakingModule := staking.NewModule(sources.StakingSource, parseCtx.EncodingConfig.Codec, db)

// Build the gov module
govModule := gov.NewModule(sources.GovSource, distrModule, mintModule, slashingModule, stakingModule, parseCtx.EncodingConfig.Codec, db)

height, err := parseCtx.Node.LatestHeight()
if err != nil {
return err
}

return govModule.UpdateParams(height)
},
}
}
39 changes: 39 additions & 0 deletions database/migrate/v6/migrate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package v6

// Migrate implements database.Migrator
func (db *Migrator) Migrate() error {
stmt := `
BEGIN;
DROP TABLE gov_params;
CREATE TABLE gov_params
(
one_row_id BOOLEAN NOT NULL DEFAULT TRUE PRIMARY KEY,
params JSONB NOT NULL,
height BIGINT NOT NULL,
CHECK (one_row_id)
);
ALTER TABLE proposal ADD COLUMN metadata TEXT NOT NULL DEFAULT '';
ALTER TABLE proposal DROP COLUMN proposal_route;
ALTER TABLE proposal DROP COLUMN proposal_type;
ALTER TABLE proposal_deposit ADD COLUMN transaction_hash TEXT NOT NULL DEFAULT '';
ALTER TABLE proposal_deposit DROP CONSTRAINT unique_deposit;
ALTER TABLE proposal_deposit ADD CONSTRAINT unique_deposit UNIQUE (proposal_id, depositor_address, transaction_hash);
ALTER TABLE proposal_vote ADD COLUMN weight TEXT NOT NULL DEFAULT '1.0';
ALTER TABLE proposal_vote DROP CONSTRAINT unique_vote;
ALTER TABLE proposal_vote ADD CONSTRAINT unique_vote UNIQUE (proposal_id, voter_address, option);
ALTER TABLE validator_voting_power ALTER COLUMN voting_power TYPE BIGINT USING voting_power::BIGINT;
ALTER TABLE proposal_validator_status_snapshot ALTER COLUMN voting_power TYPE BIGINT USING voting_power::BIGINT;
COMMIT;
`

_, err := db.SQL.Exec(stmt)

return err
}
21 changes: 21 additions & 0 deletions database/migrate/v6/migrator.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package v6

import (
"github.com/jmoiron/sqlx"

"github.com/forbole/juno/v5/database"
"github.com/forbole/juno/v5/database/postgresql"
)

var _ database.Migrator = &Migrator{}

// Migrator represents the database migrator that should be used to migrate from v4 of the database to v5
type Migrator struct {
SQL *sqlx.DB
}

func NewMigrator(db *postgresql.Database) *Migrator {
return &Migrator{
SQL: db.SQL,
}
}
6 changes: 3 additions & 3 deletions database/schema/03-staking.sql
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ CREATE INDEX validator_commission_height_index ON validator_commission (height);

CREATE TABLE validator_voting_power
(
validator_address TEXT NOT NULL REFERENCES validator (consensus_address) PRIMARY KEY,
voting_power TEXT NOT NULL,
height BIGINT NOT NULL REFERENCES block (height)
validator_address TEXT NOT NULL REFERENCES validator (consensus_address) PRIMARY KEY,
voting_power BIGINT NOT NULL,
height BIGINT NOT NULL REFERENCES block (height)
);
CREATE INDEX validator_voting_power_height_index ON validator_voting_power (height);

Expand Down
2 changes: 1 addition & 1 deletion database/top_accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

// SaveTopAccounts saves top accounts inside the database
func (db *Db) SaveTopAccounts(accounts []types.TopAccount, height int64) error {
paramsNumber := 4
paramsNumber := 3
slices := dbutils.SplitTopAccounts(accounts, paramsNumber)

for _, accounts := range slices {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.20

require (
cosmossdk.io/math v1.3.0
github.com/cheqd/cheqd-node v2.0.0-develop.10+incompatible
github.com/cheqd/cheqd-node v2.0.1+incompatible
github.com/cometbft/cometbft v0.37.4
github.com/cosmos/cosmos-sdk v0.47.10
github.com/cosmos/gogoproto v1.4.11
Expand Down
Loading

0 comments on commit e1519fd

Please sign in to comment.