|
1 | 1 | use crate::{
|
2 | 2 | spec::{ChainParams, DaLayerSpec},
|
3 |
| - types, |
| 3 | + types::{self, Hash}, |
4 | 4 | verifier::SugondatVerifier,
|
5 | 5 | };
|
6 | 6 | use async_trait::async_trait;
|
7 | 7 | use sov_rollup_interface::da::DaSpec;
|
8 |
| - |
9 |
| -use subxt::backend::rpc::{rpc_params, RpcClient}; |
10 |
| -use sugondat_subxt::sugondat::{ |
11 |
| - runtime_types::bounded_collections::bounded_vec::BoundedVec, storage, |
12 |
| -}; |
| 8 | +use sugondat_shim_common_sovereign::SovereignRPCClient; |
13 | 9 |
|
14 | 10 | mod client;
|
15 | 11 |
|
16 | 12 | use client::Client;
|
17 | 13 |
|
18 | 14 | fn default_rpc_addr() -> String {
|
19 |
| - "ws://localhost:9988/".into() |
| 15 | + "ws://localhost:10995/".into() |
20 | 16 | }
|
21 | 17 |
|
22 | 18 | /// Runtime configuration for the DA service
|
@@ -54,119 +50,25 @@ impl sov_rollup_interface::services::da::DaService for DaProvider {
|
54 | 50 | // Make an RPC call to the node to get the finalized block at the given height, if one exists.
|
55 | 51 | // If no such block exists, block until one does.
|
56 | 52 | async fn get_finalized_at(&self, height: u64) -> Result<Self::FilteredBlock, Self::Error> {
|
57 |
| - let client = self.client.clone(); |
58 |
| - let namespace = self.namespace; |
59 |
| - let client_url = client.url().await; |
60 |
| - let client = client.client().await?; |
61 |
| - |
62 |
| - loop { |
63 |
| - let finalized_head = client.backend().latest_finalized_block_ref().await?; |
64 |
| - let header = client |
65 |
| - .backend() |
66 |
| - .block_header(finalized_head.hash()) |
67 |
| - .await? |
68 |
| - .unwrap(); |
69 |
| - if header.number as u64 >= height { |
70 |
| - break; |
71 |
| - } |
72 |
| - tokio::time::sleep(std::time::Duration::from_secs(1)).await; |
73 |
| - } |
74 |
| - |
75 |
| - // between version 0.29 and 0.32 they remove subxt::rpc::Rpc |
76 |
| - // so this 'raw' rpc call is required to extract the hash of the block with a certain height |
77 |
| - let rpc_client = RpcClient::from_url(client_url).await?; |
78 |
| - let hash: subxt::utils::H256 = rpc_client |
79 |
| - .request("chain_getBlockHash", rpc_params![height]) |
80 |
| - .await?; |
81 |
| - |
82 |
| - let block = client.blocks().at(hash).await?; |
83 |
| - |
84 |
| - let header = block.header().clone(); |
85 |
| - |
86 |
| - let mut nmt_root = None; |
87 |
| - for log in &header.digest.logs { |
88 |
| - match log { |
89 |
| - subxt::config::substrate::DigestItem::Other(ref bytes) => { |
90 |
| - if bytes.starts_with(b"snmt") { |
91 |
| - nmt_root = Some(sugondat_nmt::TreeRoot::from_raw_bytes( |
92 |
| - bytes[4..].try_into().unwrap(), |
93 |
| - )); |
94 |
| - break; |
95 |
| - } |
96 |
| - } |
97 |
| - _ => {} |
98 |
| - } |
99 |
| - } |
100 |
| - |
101 |
| - // fetch timestamp from block |
102 |
| - let timestamp = block |
103 |
| - .storage() |
104 |
| - .fetch(&storage().timestamp().now()) |
105 |
| - .await? |
106 |
| - .ok_or(anyhow::anyhow!("no timestamp found"))?; |
107 |
| - |
| 53 | + let client = self.client.ensure_connected().await?; |
| 54 | + let block: sugondat_shim_common_sovereign::Block = |
| 55 | + client.get_block(height, self.namespace).await?; |
108 | 56 | let header = types::Header::new(
|
109 |
| - types::Hash(hash.0), |
110 |
| - types::Hash(header.parent_hash.0), |
111 |
| - nmt_root.unwrap(), |
112 |
| - header.number as u64, |
113 |
| - timestamp, |
| 57 | + Hash(block.block_hash), |
| 58 | + Hash(block.prev_hash), |
| 59 | + block.nmt_root, |
| 60 | + height, |
| 61 | + block.timestamp, |
114 | 62 | );
|
115 |
| - |
116 |
| - let mut transactions = vec![]; |
117 |
| - for ext in block.extrinsics().await?.iter() { |
118 |
| - let ext = ext?; |
119 |
| - let Some(address) = ext.address_bytes().map(|a| { |
120 |
| - tracing::info!("Address: {:?}", hex::encode(&a)); |
121 |
| - types::Address::try_from(&a[1..]).unwrap() |
122 |
| - }) else { |
123 |
| - continue |
124 |
| - }; |
125 |
| - let Ok(Some(submit_blob_extrinsic)) = |
126 |
| - ext.as_extrinsic::<sugondat_subxt::sugondat::blobs::calls::types::SubmitBlob>() |
127 |
| - else { |
128 |
| - // Not a submit blob extrinsic, skip. |
129 |
| - continue |
130 |
| - }; |
131 |
| - |
132 |
| - if submit_blob_extrinsic.namespace_id != namespace.namespace_id() { |
133 |
| - // Not for our app. |
134 |
| - continue; |
135 |
| - } |
136 |
| - |
137 |
| - let blob_data = submit_blob_extrinsic.blob.0; |
138 |
| - tracing::info!("received a blob: {}", hex::encode(&blob_data)); |
139 |
| - transactions.push(types::BlobTransaction::new(address, blob_data)); |
140 |
| - } |
141 |
| - |
142 |
| - let address = sugondat_subxt::sugondat::blobs::storage::StorageApi.blob_list(); |
143 |
| - let blobs = client |
144 |
| - .storage() |
145 |
| - .at(hash) |
146 |
| - .fetch(&address) |
147 |
| - .await |
148 |
| - .unwrap() |
149 |
| - .map(|x| x.0) |
150 |
| - .unwrap_or_default(); |
151 |
| - |
152 |
| - let blobs = blobs |
| 63 | + let transactions = block |
| 64 | + .blobs |
153 | 65 | .into_iter()
|
154 |
| - .map(|blob| sugondat_nmt::BlobMetadata { |
155 |
| - namespace: sugondat_nmt::Namespace::with_namespace_id(blob.namespace_id), |
156 |
| - leaf: sugondat_nmt::NmtLeaf { |
157 |
| - extrinsic_index: blob.extrinsic_index, |
158 |
| - who: blob.who.0, |
159 |
| - blob_hash: blob.blob_hash, |
160 |
| - }, |
161 |
| - }) |
| 66 | + .map(|blob| types::BlobTransaction::new(types::Address(blob.sender), blob.data)) |
162 | 67 | .collect();
|
163 |
| - let mut tree = sugondat_nmt::tree_from_blobs(blobs); |
164 |
| - let blob_proof = tree.proof(namespace); |
165 |
| - |
166 | 68 | Ok(types::Block {
|
167 | 69 | header,
|
168 | 70 | transactions,
|
169 |
| - blob_proof, |
| 71 | + blob_proof: block.proof, |
170 | 72 | })
|
171 | 73 | }
|
172 | 74 |
|
@@ -200,25 +102,8 @@ impl sov_rollup_interface::services::da::DaService for DaProvider {
|
200 | 102 |
|
201 | 103 | // Send the blob to the DA layer, using the submit_blob extrinsic
|
202 | 104 | async fn send_transaction(&self, blob: &[u8]) -> Result<(), Self::Error> {
|
203 |
| - let client = self.client.clone(); |
204 |
| - let blob = blob.to_vec(); |
205 |
| - let namespace_id = self.namespace.namespace_id(); |
206 |
| - use subxt_signer::sr25519::dev; |
207 |
| - |
208 |
| - let client = client.client().await?; |
209 |
| - |
210 |
| - let extrinsic = sugondat_subxt::sugondat::tx() |
211 |
| - .blobs() |
212 |
| - .submit_blob(namespace_id, BoundedVec(blob)); |
213 |
| - |
214 |
| - let from = dev::alice(); |
215 |
| - let _events = client |
216 |
| - .tx() |
217 |
| - .sign_and_submit_then_watch_default(&extrinsic, &from) |
218 |
| - .await? |
219 |
| - .wait_for_finalized_success() |
220 |
| - .await?; |
221 |
| - |
| 105 | + let client = self.client.ensure_connected().await?; |
| 106 | + client.submit_blob(blob.to_vec(), self.namespace).await?; |
222 | 107 | Ok(())
|
223 | 108 | }
|
224 | 109 | }
|
0 commit comments