From f91ca05ef7cf46024be5ee25ae70012012e329cd Mon Sep 17 00:00:00 2001 From: Mateusz Jasiuk Date: Mon, 14 Oct 2024 10:43:14 +0200 Subject: [PATCH] feat: add cubic_slashing_window_length (#131) * feat: add add_cubic_slashing_window_length * ci: update deploy workflow --------- Co-authored-by: Gianmarco Fraccaroli --- .github/workflows/deploy.yml | 17 +++++++++-------- .github/workflows/queue_and_merge.yml | 2 +- .github/workflows/scripts/update-package.py | 2 +- .../down.sql | 1 + .../up.sql | 2 ++ orm/src/parameters.rs | 5 +++++ orm/src/schema.rs | 1 + parameters/src/repository/parameters.rs | 2 ++ parameters/src/services/namada.rs | 2 ++ shared/src/parameters.rs | 1 + swagger-codegen.json | 2 +- swagger.yml | 4 +++- webserver/src/response/chain.rs | 4 ++++ 13 files changed, 33 insertions(+), 12 deletions(-) create mode 100644 orm/migrations/2024-10-14-073203_add_cubic_slashing_window_length/down.sql create mode 100644 orm/migrations/2024-10-14-073203_add_cubic_slashing_window_length/up.sql diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 9dabb927..cca1a919 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -59,7 +59,7 @@ jobs: password: ${{ secrets.GITHUB_TOKEN }} - name: Build and Push id: push - uses: docker/build-push-action@v5 + uses: docker/build-push-action@v6 with: context: . file: ${{ matrix.docker.context }}/Dockerfile @@ -70,20 +70,21 @@ jobs: cache-to: type=gha,mode=max swagger-npm-package: - runs-on: macos-latest + runs-on: ubuntu-latest steps: - id: get_version uses: battila7/get-version-action@v2 - - name: Install swagger codegen - run: brew install swagger-codegen - uses: actions/setup-node@v4 with: node-version: 20 - name: Authenticate with private NPM package run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc - - name: Generate client - run: swagger-codegen generate -i swagger.yml -l javascript -o ./code + - name: Generate Typescript Client + uses: openapi-generators/openapitools-generator-action@v1 + with: + generator: typescript-axios + openapi-file: swagger.yml - name: Update package.json - run: python3 .github/workflows/scripts/update-package.py code/package.json ${{ steps.get_version.outputs.version-without-v }} + run: python3 .github/workflows/scripts/update-package.py typescript-axios/package.json ${{ steps.get_version.outputs.version-without-v }} - name: Publish package - run: npm publish --access public --verbose \ No newline at end of file + run: cd typescript-axios && npm publish --access public --verbose \ No newline at end of file diff --git a/.github/workflows/queue_and_merge.yml b/.github/workflows/queue_and_merge.yml index 139bc273..d01c8792 100644 --- a/.github/workflows/queue_and_merge.yml +++ b/.github/workflows/queue_and_merge.yml @@ -77,7 +77,7 @@ jobs: steps: - uses: actions/checkout@v4 - name: Validate OpenAPI definition - uses: char0n/swagger-editor-validate@v1.3.2 + uses: swaggerexpert/swagger-editor-validate@v1 with: definition-file: swagger.yml diff --git a/.github/workflows/scripts/update-package.py b/.github/workflows/scripts/update-package.py index cd2593e8..24d6ce29 100644 --- a/.github/workflows/scripts/update-package.py +++ b/.github/workflows/scripts/update-package.py @@ -9,7 +9,7 @@ package_json['name'] = "namada-indexer-client" package_json['version'] = package_version package_json['description'] = "Set of API to interact with a namada indexer." -package_json['license'] = " GPL-3.0 license" +package_json['license'] = "GPL-3.0 license" with open(package_json_path, 'w', encoding='utf-8') as f: json.dump(package_json, f, ensure_ascii=False, indent=4) \ No newline at end of file diff --git a/orm/migrations/2024-10-14-073203_add_cubic_slashing_window_length/down.sql b/orm/migrations/2024-10-14-073203_add_cubic_slashing_window_length/down.sql new file mode 100644 index 00000000..d9a93fe9 --- /dev/null +++ b/orm/migrations/2024-10-14-073203_add_cubic_slashing_window_length/down.sql @@ -0,0 +1 @@ +-- This file should undo anything in `up.sql` diff --git a/orm/migrations/2024-10-14-073203_add_cubic_slashing_window_length/up.sql b/orm/migrations/2024-10-14-073203_add_cubic_slashing_window_length/up.sql new file mode 100644 index 00000000..d37a8890 --- /dev/null +++ b/orm/migrations/2024-10-14-073203_add_cubic_slashing_window_length/up.sql @@ -0,0 +1,2 @@ +ALTER TABLE chain_parameters +ADD COLUMN cubic_slashing_window_length INT NOT NULL DEFAULT 0; diff --git a/orm/src/parameters.rs b/orm/src/parameters.rs index 7438f8ed..4ec51a26 100644 --- a/orm/src/parameters.rs +++ b/orm/src/parameters.rs @@ -25,6 +25,7 @@ pub struct ParametersInsertDb { pub genesis_time: i64, pub checksums: SerdeJSONValue, pub epoch_switch_blocks_delay: i32, + pub cubic_slashing_window_length: i32, } #[derive(Serialize, Queryable, Selectable, Clone)] @@ -44,6 +45,7 @@ pub struct ParametersDb { pub genesis_time: i64, pub checksums: SerdeJSONValue, pub epoch_switch_blocks_delay: i32, + pub cubic_slashing_window_length: i32, } impl From<(Parameters, Genesis, Checksums, EpochSwitchBlocksDelay)> @@ -71,6 +73,9 @@ impl From<(Parameters, Genesis, Checksums, EpochSwitchBlocksDelay)> checksums: serde_json::to_value(checksums) .expect("Failed to serialize checksums"), epoch_switch_blocks_delay: epoch_switch_blocks_delay as i32, + cubic_slashing_window_length: parameters + .cubic_slashing_window_length + as i32, } } } diff --git a/orm/src/schema.rs b/orm/src/schema.rs index 469ef7b8..20f6773b 100644 --- a/orm/src/schema.rs +++ b/orm/src/schema.rs @@ -109,6 +109,7 @@ diesel::table! { genesis_time -> Int8, epoch_switch_blocks_delay -> Int4, checksums -> Jsonb, + cubic_slashing_window_length -> Int4, } } diff --git a/parameters/src/repository/parameters.rs b/parameters/src/repository/parameters.rs index 40787097..1c769ef9 100644 --- a/parameters/src/repository/parameters.rs +++ b/parameters/src/repository/parameters.rs @@ -17,6 +17,8 @@ pub fn upsert_chain_parameters( chain_parameters::apr.eq(excluded(chain_parameters::apr)), chain_parameters::max_block_time .eq(excluded(chain_parameters::max_block_time)), + chain_parameters::cubic_slashing_window_length + .eq(excluded(chain_parameters::cubic_slashing_window_length)), )) .execute(transaction_conn) .context("Failed to update chain_parameters state in db")?; diff --git a/parameters/src/services/namada.rs b/parameters/src/services/namada.rs index 67d0fa69..21bebaf4 100644 --- a/parameters/src/services/namada.rs +++ b/parameters/src/services/namada.rs @@ -97,6 +97,8 @@ pub async fn get_parameters(client: &HttpClient) -> anyhow::Result { max_block_time: max_block_time.0, apr: apr.to_string(), native_token_address: native_token_address.to_string(), + cubic_slashing_window_length: pos_parameters + .cubic_slashing_window_length, }) } diff --git a/shared/src/parameters.rs b/shared/src/parameters.rs index 59c797b9..967bb618 100644 --- a/shared/src/parameters.rs +++ b/shared/src/parameters.rs @@ -8,6 +8,7 @@ pub struct Parameters { pub min_duration: u64, pub apr: String, pub native_token_address: String, + pub cubic_slashing_window_length: u64, } pub type EpochSwitchBlocksDelay = u32; diff --git a/swagger-codegen.json b/swagger-codegen.json index 370fac27..54333f50 100644 --- a/swagger-codegen.json +++ b/swagger-codegen.json @@ -1,5 +1,5 @@ { "npmName": "@anomaorg/namada-indexer-client", - "npmVersion": "0.0.26" + "npmVersion": "0.0.27" } diff --git a/swagger.yml b/swagger.yml index 36580f22..45d2d9dc 100644 --- a/swagger.yml +++ b/swagger.yml @@ -847,7 +847,7 @@ components: type: string Parameters: type: object - required: [unbondingLength, pipelineLength, epochsPerYear, apr, nativeTokenAddress, chainId, genesisTime, minDuration, minNumOfBlocks, maxBlockTime, checksums, epochSwitchBlocksDelay] + required: [unbondingLength, pipelineLength, epochsPerYear, apr, nativeTokenAddress, chainId, genesisTime, minDuration, minNumOfBlocks, maxBlockTime, checksums, epochSwitchBlocksDelay, cubicSlashingWindowLength] properties: unbondingLength: type: string @@ -875,6 +875,8 @@ components: type: string epochSwitchBlocksDelay: type: string + cubicSlashingWindowLength: + type: string RpcUrl: type: object required: [url] diff --git a/webserver/src/response/chain.rs b/webserver/src/response/chain.rs index 84cc6927..ecaebdff 100644 --- a/webserver/src/response/chain.rs +++ b/webserver/src/response/chain.rs @@ -18,6 +18,7 @@ pub struct Parameters { pub max_block_time: String, pub checksums: SerdeJSONValue, pub epoch_switch_blocks_delay: String, + pub cubic_slashing_window_length: String, } impl From for Parameters { @@ -37,6 +38,9 @@ impl From for Parameters { epoch_switch_blocks_delay: parameters .epoch_switch_blocks_delay .to_string(), + cubic_slashing_window_length: parameters + .cubic_slashing_window_length + .to_string(), } } }