Skip to content

Commit fbf62e6

Browse files
committed
Merge branch 'vmarkushin/refactor-tendermint+zk' into rustnninja/fix-tm-validation-on-yui
2 parents 4283d5a + 438c6e7 commit fbf62e6

19 files changed

+1006
-623
lines changed

.github/workflows/docker-image-hyperspace.yml

+24-5
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,23 @@ jobs:
4848
- name: Set up Docker Buildx
4949
uses: docker/setup-buildx-action@v3
5050

51-
- name: Extract metadata (tags, labels) for Docker
52-
id: meta
51+
- name: Extract metadata (tags, labels) for Docker (tag)
52+
id: meta-tag
53+
if: github.ref_type == 'tag'
5354
uses: docker/metadata-action@v5
5455
with:
5556
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
5657
tags: |
5758
type=semver,pattern={{version}}
5859
type=semver,pattern={{major}}.{{minor}}
60+
61+
- name: Extract metadata (tags, labels) for Docker (branch)
62+
id: meta-branch
63+
if: github.ref_type == 'branch'
64+
uses: docker/metadata-action@v5
65+
with:
66+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
67+
tags: |
5968
type=ref,event=branch
6069
type=sha,prefix={{branch}}-
6170
@@ -66,10 +75,20 @@ jobs:
6675
username: ${{ github.repository_owner }}
6776
password: ${{ secrets.GITHUB_TOKEN }}
6877

69-
- name: Build and push Docker image
78+
- name: Build and push Docker image (tag)
79+
if: github.ref_type == 'tag'
80+
uses: docker/build-push-action@v5
81+
with:
82+
file: scripts/hyperspace.Dockerfile
83+
push: ${{ github.event_name != 'pull_request' }}
84+
tags: ${{ steps.meta-tag.outputs.tags }}
85+
labels: ${{ steps.meta-tag.outputs.labels }}
86+
87+
- name: Build and push Docker image (branch)
88+
if: github.ref_type == 'branch'
7089
uses: docker/build-push-action@v5
7190
with:
7291
file: scripts/hyperspace.Dockerfile
7392
push: ${{ github.event_name != 'pull_request' }}
74-
tags: ${{ steps.meta.outputs.tags }}
75-
labels: ${{ steps.meta.outputs.labels }}
93+
tags: ${{ steps.meta-branch.outputs.tags }}
94+
labels: ${{ steps.meta-branch.outputs.labels }}

.github/workflows/docker-image-indexer.yml

+30-2
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,23 @@ jobs:
4848
- name: Set up Docker Buildx
4949
uses: docker/setup-buildx-action@v3
5050

51-
- name: Extract metadata (tags, labels) for Docker
52-
id: meta
51+
- name: Extract metadata (tags, labels) for Docker (tag)
52+
id: meta-tag
53+
if: github.ref_type == 'tag'
5354
uses: docker/metadata-action@v5
5455
with:
5556
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
5657
tags: |
5758
type=semver,pattern={{version}}
5859
type=semver,pattern={{major}}.{{minor}}
60+
61+
- name: Extract metadata (tags, labels) for Docker (branch)
62+
id: meta-branch
63+
if: github.ref_type == 'branch'
64+
uses: docker/metadata-action@v5
65+
with:
66+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
67+
tags: |
5968
type=ref,event=branch
6069
type=sha,prefix={{branch}}-
6170
@@ -73,3 +82,22 @@ jobs:
7382
push: ${{ github.event_name != 'pull_request' }}
7483
tags: ${{ steps.meta.outputs.tags }}
7584
labels: ${{ steps.meta.outputs.labels }}
85+
86+
87+
- name: Build and push Docker image (tag)
88+
if: github.ref_type == 'tag'
89+
uses: docker/build-push-action@v5
90+
with:
91+
file: scripts/indexer.Dockerfile
92+
push: ${{ github.event_name != 'pull_request' }}
93+
tags: ${{ steps.meta-tag.outputs.tags }}
94+
labels: ${{ steps.meta-tag.outputs.labels }}
95+
96+
- name: Build and push Docker image (branch)
97+
if: github.ref_type == 'branch'
98+
uses: docker/build-push-action@v5
99+
with:
100+
file: scripts/indexer.Dockerfile
101+
push: ${{ github.event_name != 'pull_request' }}
102+
tags: ${{ steps.meta-branch.outputs.tags }}
103+
labels: ${{ steps.meta-branch.outputs.labels }}

hyperspace/cosmos/src/client.rs

+14-18
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use super::{
77
use crate::{error::Error, eth_zk_utils::ZKProver};
88
use bech32::ToBase32;
99
use bip32::{DerivationPath, ExtendedPrivateKey, XPrv, XPub as ExtendedPublicKey};
10-
use core::{convert::{From, Into, TryFrom}, time};
10+
use core::convert::{From, Into, TryFrom};
1111
use digest::Digest;
1212
use ibc::core::{
1313
ics02_client::height::Height,
@@ -188,21 +188,17 @@ pub struct CosmosClient<H> {
188188
}
189189

190190
#[derive(Clone, Debug)]
191-
pub struct ZkProofRequest{
191+
pub struct ZkProofRequest {
192192
pub proof_id: String,
193193
pub request_time: std::time::SystemTime,
194194
pub bitmask: u64,
195195
}
196196

197-
impl ZkProofRequest{
197+
impl ZkProofRequest {
198198
pub fn new(proof_id: String, bitmask: u64) -> Self {
199-
Self {
200-
proof_id,
201-
request_time: std::time::SystemTime::now(),
202-
bitmask,
203-
}
199+
Self { proof_id, request_time: std::time::SystemTime::now(), bitmask }
204200
}
205-
pub fn is_waiting_for_proof_too_long(&self, possible_delay_secs: u64 ) -> bool {
201+
pub fn is_waiting_for_proof_too_long(&self, possible_delay_secs: u64) -> bool {
206202
let t = std::time::SystemTime::now();
207203
let diff = t.duration_since(self.request_time.clone()).unwrap();
208204
if diff.as_secs() > possible_delay_secs {
@@ -212,21 +208,18 @@ impl ZkProofRequest{
212208
}
213209
}
214210

215-
216211
#[derive(Clone, Default)]
217212
pub struct MockZkProover {
218-
pub map_height_time : HashMap<Height, std::time::SystemTime>,
213+
pub map_height_time: HashMap<Height, std::time::SystemTime>,
219214
}
220215

221-
impl MockZkProover{
216+
impl MockZkProover {
222217
fn new() -> Self {
223-
Self {
224-
map_height_time : HashMap::new(),
225-
}
218+
Self { map_height_time: HashMap::new() }
226219
}
227220

228221
pub fn request(&mut self, height: Height) {
229-
if self.map_height_time.contains_key(&height){
222+
if self.map_height_time.contains_key(&height) {
230223
return;
231224
}
232225

@@ -246,7 +239,6 @@ impl MockZkProover{
246239
}
247240
return false;
248241
}
249-
250242
}
251243

252244
/// config options for [`ParachainClient`]
@@ -385,7 +377,11 @@ where
385377
join_handles: Arc::new(TokioMutex::new(vec![ws_driver_jh])),
386378
mock_zk_prover: Arc::new(Mutex::new(MockZkProover::new())),
387379
zk_proof_requests: Arc::new(Mutex::new(HashMap::new())),
388-
zk_prover_api: ZKProver::new(config.zk_prover_remote_uri, Duration::from_secs(config.zk_prover_allowed_delay_secs).as_secs(), config.zk_val_len),
380+
zk_prover_api: ZKProver::new(
381+
config.zk_prover_remote_uri,
382+
Duration::from_secs(config.zk_prover_allowed_delay_secs).as_secs(),
383+
config.zk_val_len,
384+
),
389385
})
390386
}
391387

hyperspace/cosmos/src/eth_zk_utils.rs

+23-30
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
use anyhow::{anyhow, Error};
2-
use std::{
3-
thread,
4-
time::{Duration, SystemTime},
5-
};
62
use ureq;
73

84
#[derive(Debug, Clone)]
@@ -31,41 +27,38 @@ pub struct CreateProofInput {
3127
pub height: u64,
3228
}
3329

34-
impl CreateProofInput{
35-
pub fn new(signatures: Vec<Vec<u8>>, msgs: Vec<Vec<u8>>, public_keys: Vec<Vec<u8>>, height: u64) -> Self {
30+
impl CreateProofInput {
31+
pub fn new(
32+
signatures: Vec<Vec<u8>>,
33+
msgs: Vec<Vec<u8>>,
34+
public_keys: Vec<Vec<u8>>,
35+
height: u64,
36+
) -> Self {
3637
Self { signatures, msgs, public_keys, height }
3738
}
3839
}
3940

4041
impl ZKProver {
4142
pub fn new(prover_url: String, delay_secs: u64, zk_val_len: usize) -> Self {
42-
Self { prover_url, delay_secs: delay_secs, zk_val_len: zk_val_len }
43+
Self { prover_url, delay_secs, zk_val_len }
4344
}
4445

45-
pub fn status(&self) -> Result<String, Error> {
46-
let url = format!("{}{}", self.prover_url, "/status");
47-
let result= ureq::get(url.as_str())
48-
.call()?
49-
.into_string()?;
50-
Ok(result)
46+
pub fn status(&self) -> Result<String, Error> {
47+
let url = format!("{}{}", self.prover_url, "/status");
48+
let result = ureq::get(url.as_str()).call()?.into_string()?;
49+
Ok(result)
5150
}
5251

53-
54-
5552
pub fn create_proof(&self, proof_input: CreateProofInput) -> Result<Response, Error> {
56-
let url = format!("{}{}", self.prover_url, "/create_proof");
57-
let result= ureq::post(url.as_str())
58-
.send_json(ureq::json!(proof_input))?
59-
.into_string();
60-
match result {
61-
Ok(r) => {
62-
let resp: Response = serde_json::from_str(&r)?;
63-
Ok(resp)
64-
},
65-
Err(e) => {
66-
Err(anyhow!("Error: {:?}", e))
67-
}
68-
}
53+
let url = format!("{}{}", self.prover_url, "/create_proof");
54+
let result = ureq::post(url.as_str()).send_json(ureq::json!(proof_input))?.into_string();
55+
match result {
56+
Ok(r) => {
57+
let resp: Response = serde_json::from_str(&r)?;
58+
Ok(resp)
59+
},
60+
Err(e) => Err(anyhow!("Error: {:?}", e)),
61+
}
6962
}
7063

7164
pub fn poll_proof(&self, proof_id: &str, height: u64) -> Result<Option<String>, Error> {
@@ -77,12 +70,12 @@ impl ZKProver {
7770
}))?
7871
.into_string()?;
7972

80-
let resp: ResponseProofRequest = serde_json::from_str(&resp)?;
73+
let resp: ResponseProofRequest = serde_json::from_str(&resp)?;
8174

8275
// TOOD: handle some edge cases
8376
match resp.status.as_str() {
8477
"COMPLETED" => Ok(resp.proof),
8578
_ => Ok(None),
8679
}
8780
}
88-
}
81+
}

0 commit comments

Comments
 (0)