Skip to content

Commit

Permalink
feat: add cubic_slashing_window_length (#131)
Browse files Browse the repository at this point in the history
* feat: add add_cubic_slashing_window_length

* ci: update deploy workflow

---------

Co-authored-by: Gianmarco Fraccaroli <[email protected]>
  • Loading branch information
mateuszjasiuk and Fraccaman authored Oct 14, 2024
1 parent 667abcf commit f91ca05
Show file tree
Hide file tree
Showing 13 changed files with 33 additions and 12 deletions.
17 changes: 9 additions & 8 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
run: cd typescript-axios && npm publish --access public --verbose
2 changes: 1 addition & 1 deletion .github/workflows/queue_and_merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/scripts/update-package.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-- This file should undo anything in `up.sql`
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE chain_parameters
ADD COLUMN cubic_slashing_window_length INT NOT NULL DEFAULT 0;
5 changes: 5 additions & 0 deletions orm/src/parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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)>
Expand Down Expand Up @@ -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,
}
}
}
1 change: 1 addition & 0 deletions orm/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ diesel::table! {
genesis_time -> Int8,
epoch_switch_blocks_delay -> Int4,
checksums -> Jsonb,
cubic_slashing_window_length -> Int4,
}
}

Expand Down
2 changes: 2 additions & 0 deletions parameters/src/repository/parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")?;
Expand Down
2 changes: 2 additions & 0 deletions parameters/src/services/namada.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ pub async fn get_parameters(client: &HttpClient) -> anyhow::Result<Parameters> {
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,
})
}

Expand Down
1 change: 1 addition & 0 deletions shared/src/parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
2 changes: 1 addition & 1 deletion swagger-codegen.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"npmName": "@anomaorg/namada-indexer-client",
"npmVersion": "0.0.26"
"npmVersion": "0.0.27"
}

4 changes: 3 additions & 1 deletion swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -875,6 +875,8 @@ components:
type: string
epochSwitchBlocksDelay:
type: string
cubicSlashingWindowLength:
type: string
RpcUrl:
type: object
required: [url]
Expand Down
4 changes: 4 additions & 0 deletions webserver/src/response/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ParametersDb> for Parameters {
Expand All @@ -37,6 +38,9 @@ impl From<ParametersDb> for Parameters {
epoch_switch_blocks_delay: parameters
.epoch_switch_blocks_delay
.to_string(),
cubic_slashing_window_length: parameters
.cubic_slashing_window_length
.to_string(),
}
}
}
Expand Down

0 comments on commit f91ca05

Please sign in to comment.