Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions batcher/aligned/test_files/mina/mina_protocol_state_query.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"data": {
"bestChain": [
{
"protocolState": {
"previousStateHash": "3NKSvjaGSKiQuAt8BP1b1VCpLbJc9RcEFjYCaBYsJJFdrtd6tpaV",
"blockchainState": {
"bodyReference": "36bda176656cc3be96c3d317db7b4ac06fdbc7f4eedcd6efdd20e28143d67421",
"snarkedLedgerHash": "jx3ye7cdFTTvFV22wJWfCyrDwMcoWUonp1H3LSmXNG1DFmctM35",
"date": "1720015456000",
"stagedLedgerAuxHash": "UDRUFHSvxUAtV8sh7gzMVPqpbd46roG1wzWR6dYvB6RunPihom",
"stagedLedgerHash": "jx3ye7cdFTTvFV22wJWfCyrDwMcoWUonp1H3LSmXNG1DFmctM35",
"stagedLedgerPendingCoinbaseAux": "WAAeUjUnP9Q2JiabhJzJozcjiEmkZe8ob4cfFKSuq6pQSNmHh7",
"stagedLedgerPendingCoinbaseHash": "2mzvU1MA5JjDUrLsKk6KFFj4CPn6bnHjN5Fi779U96JUbZNwoTvF",
"stagedLedgerProofEmitted": false,
"utcDate": "1720015456000"
},
"consensusState": {
"blockHeight": "296372",
"blockCreator": "B62qiy32p8kAKnny8ZFwoMhYpBppM1DWVCqAPBYNcXnsAHhnfAAuXgg",
"blockStakeWinner": "B62qiy32p8kAKnny8ZFwoMhYpBppM1DWVCqAPBYNcXnsAHhnfAAuXgg",
"blockchainLength": "296372",
"coinbaseReceiever": "B62qiy32p8kAKnny8ZFwoMhYpBppM1DWVCqAPBYNcXnsAHhnfAAuXgg",
"epoch": "0",
"epochCount": "0",
"hasAncestorInSameCheckpointWindow": true,
"lastVrfOutput": "48HHqTLpPf8qcQQ7Js9U4jxAoX4omY2prxAZ18V4TWeqFPVgJULH",
"minWindowDensity": "77",
"slot": "0",
"slotSinceGenesis": "445860",
"superchargedCoinbase": true,
"totalCurrency": "30000000001000",
"nextEpochData": {
"epochLength": "2",
"lockCheckpoint": "3NKqaKwLMFvzrMU9i4LguPhTdPKfExNbD9GSgMu7ZcNF2mxVGT5a",
"seed": "2vaJXTJckyEgDeTbMPfU3eWVuxonXNg9s1mnsoDyH6JFuSu7dEkn",
"startCheckpoint": "3NK2tkzqqK5spR2sZ7tujjqPksL45M3UUrcA4WhCkeiPtnugyE2x",
"ledger": {
"hash": "jxjmYHK1tnGy5S6CDaLDTRrDbw17DmtEd6Jnw3L86QSsLm15w5g",
"totalCurrency": "1404240804000001000"
}
},
"stakingEpochData": {
"epochLength": "1",
"seed": "2vbdR3vZUxh8NFnsnrefko7YCiLUKNPUbQpqSQAFXFijtTjd3531",
"lockCheckpoint": "3NK2tkzqqK5spR2sZ7tujjqPksL45M3UUrcA4WhCkeiPtnugyE2x",
"startCheckpoint": "3NK2tkzqqK5spR2sZ7tujjqPksL45M3UUrcA4WhCkeiPtnugyE2x",
"ledger": {
"hash": "jxvdSnpgWjjERJFdcYNxChJ9F39v4tGrNSzDcaQXuXeJnicrYEP",
"totalCurrency": "1397164660000001000"
}
}
}
}
}
]
}
}
2 changes: 2 additions & 0 deletions operator/mina/lib/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions operator/mina/lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ rmp-serde = "1.1.2"
serde_json = "1.0.118"
hex = "0.4.3"
mina-tree = { git = "https://github.com/lambdaclass/openmina/", branch = "mina_bridge" }
mina-p2p-messages = { git = "https://github.com/lambdaclass/openmina/", branch = "mina_bridge" }
bs58 = "0.4.0"

[patch.crates-io]
ark-ff = { git = "https://github.com/openmina/algebra", branch = "openmina" }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
use mina_p2p_messages::{
binprot::BinProtRead,
v2::{
ConsensusBodyReferenceStableV1, MinaBaseStagedLedgerHashStableV1,
MinaStateBlockchainStateValueStableV2,
},
};
use serde::Deserialize;

#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct BlockchainState {
pub staged_ledger_hash: String,
pub body_reference: String,
}

impl Into<MinaStateBlockchainStateValueStableV2> for BlockchainState {
fn into(self) -> MinaStateBlockchainStateValueStableV2 {
let staged_ledger_hash = parse_staged_ledger_hash(self.staged_ledger_hash).unwrap();
// This value is in hex format
let body_reference = ConsensusBodyReferenceStableV1(self.body_reference.as_str().into());
MinaStateBlockchainStateValueStableV2 {
staged_ledger_hash,
genesis_ledger_hash: todo!(),
ledger_proof_statement: todo!(),
timestamp: todo!(),
body_reference,
}
}
}

fn parse_staged_ledger_hash(
input: String,
) -> Result<MinaBaseStagedLedgerHashStableV1, mina_p2p_messages::binprot::Error> {
let mut decoded = &bs58::decode(input).into_vec().unwrap()[1..];
MinaBaseStagedLedgerHashStableV1::binprot_read(&mut decoded)
}
3 changes: 3 additions & 0 deletions operator/mina/lib/src/openmina_block_verifier/header/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub mod blockchain_state;
pub mod protocol_state;
pub mod protocol_state_query;
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use std::str::FromStr as _;

use mina_p2p_messages::v2::{
MinaStateProtocolStateBodyValueStableV2, MinaStateProtocolStateValueStableV2, StateHash,
};
use serde::Deserialize;

use super::blockchain_state::BlockchainState;

#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct ProtocolState {
pub previous_state_hash: String,
pub blockchain_state: BlockchainState,
}

impl Into<MinaStateProtocolStateValueStableV2> for ProtocolState {
fn into(self) -> MinaStateProtocolStateValueStableV2 {
let previous_state_hash = StateHash::from_str(&self.previous_state_hash).unwrap();
let body = MinaStateProtocolStateBodyValueStableV2 {
genesis_state_hash: todo!(),
blockchain_state: self.blockchain_state.into(),
consensus_state: todo!(),
constants: todo!(),
};

MinaStateProtocolStateValueStableV2 {
previous_state_hash,
body: todo!(),
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use serde::Deserialize;

use super::protocol_state::ProtocolState;

#[derive(Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ProtocolStateQuery {
pub data: Data,
}

#[derive(Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Data {
pub best_chain: [BestChain; 1],
}

#[derive(Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct BestChain {
pub protocol_state: ProtocolState,
}
24 changes: 21 additions & 3 deletions operator/mina/lib/src/openmina_block_verifier/mod.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,35 @@
pub fn parse_query_to_mina_block_header(mina_state_proof_vk_query: &str) {
todo!()
pub mod header;

use header::protocol_state_query::ProtocolStateQuery;
use mina_p2p_messages::v2::MinaStateProtocolStateValueStableV2;

pub fn parse_query_to_mina_block_header(
mina_protocol_state_query: &str,
_mina_state_proof_vk_query: &str,
) {
let protocol_state_query: ProtocolStateQuery =
serde_json::from_str(mina_protocol_state_query).unwrap();
let _protocol_state: MinaStateProtocolStateValueStableV2 = protocol_state_query.data.best_chain
[0]
.clone()
.protocol_state
.into();
}

#[cfg(test)]
mod test {
use super::parse_query_to_mina_block_header;

const MINA_PROTOCOL_STATE_QUERY: &str = include_str!(
"../../../../../batcher/aligned/test_files/mina/mina_protocol_state_query.json"
);

const MINA_STATE_PROOF_VK_QUERY: &str = include_str!(
"../../../../../batcher/aligned/test_files/mina/mina_state_proof_vk_query.json"
);

#[test]
fn test_parse_query_to_mina_block_header() {
parse_query_to_mina_block_header(MINA_STATE_PROOF_VK_QUERY);
parse_query_to_mina_block_header(MINA_PROTOCOL_STATE_QUERY, MINA_STATE_PROOF_VK_QUERY);
}
}