Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Net/dev - Small fixes + lint #26

Merged
merged 3 commits into from
Aug 29, 2023
Merged
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
41 changes: 11 additions & 30 deletions crates/client/data-availability/src/bitcoin/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,7 @@ pub mod config;

use anyhow::Result;
use async_trait::async_trait;
use bitcoin_da::Config as BitcoinDAConfig;
// use bitcoin::hash_types::Txid;
// use bitcoin::key::{PrivateKey, PublicKey};
// use bitcoin::script::PushBytesBuf;
// use bitcoin::secp256k1::{All, KeyPair, Secp256k1, SecretKey, XOnlyPublicKey};
// use bitcoin::taproot::{LeafVersion, NodeInfo, TapTree, TaprootBuilder};
// use bitcoin::{opcodes, script as txscript, sighash, Network, OutPoint, ScriptBuf, Transaction, TxIn, TxOut,
// Witness};
use bitcoin_da::Relayer;
use bitcoin_da::{Config as BitcoinDAConfig, Relayer};
use bitcoincore_rpc::bitcoincore_rpc_json::{GetTransactionResultDetailCategory, ListTransactionResult};
// Bitcoincore RPC imports
use bitcoincore_rpc::RpcApi;
Expand All @@ -21,7 +13,7 @@ use ethers::types::{I256, U256};
use crate::utils::is_valid_http_endpoint;
use crate::{DaClient, DaMode};

// #[derive(Clone, Debug)]
// #[derive(Clone)]
pub struct BitcoinClient {
relayer: Relayer,
mode: DaMode,
Expand Down Expand Up @@ -59,27 +51,21 @@ impl DaClient for BitcoinClient {
last_tx.iter().filter(|tx| tx.detail.category == GetTransactionResultDetailCategory::Send).collect();
filtered_txs.sort_by(|a, b| a.info.blockheight.cmp(&b.info.blockheight));
let most_recent_tx = filtered_txs.last();
let most_recent_block_hash = match most_recent_tx.map_or(None, |tx| tx.info.blockhash) {
None => return Err(anyhow::anyhow!("No transactions found")),
Some(hash) => hash,
};
let txid = match most_recent_tx {
None => return Err(anyhow::anyhow!("No transactions found")),
Some(tx) => Some(tx.info.txid),
};


let last_data_raw = match most_recent_tx {
Some(tx) => self.relayer.read_transaction(&tx.info.txid, Some(&most_recent_block_hash))
.map_err(|e| anyhow::anyhow!("bitcoin read err: {e}"))?,
Some(tx) => self
.relayer
.read_transaction(&tx.info.txid, tx.info.blockhash.as_ref())
.map_err(|e| anyhow::anyhow!("bitcoin read err: {e}"))?,
None => return Err(anyhow::anyhow!("No transactions found")),
};

// change to rollup height
Ok(I256::from(1))
}

fn get_mode(&self) -> DaMode {
self.mode
self.mode.clone()
}
}

Expand All @@ -89,14 +75,9 @@ impl BitcoinClient {
return Err(format!("invalid http endpoint, received {}", &conf.host));
}

let bitcoin_da_conf: BitcoinDAConfig = BitcoinDAConfig {
host: conf.host,
user: conf.user,
pass: conf.pass,
};
let bitcoin_da_conf: BitcoinDAConfig = BitcoinDAConfig { host: conf.host, user: conf.user, pass: conf.pass };

let client: Relayer =
Relayer::new(&bitcoin_da_conf).map_err(|e| format!("bitcoin new relayer err: {e}"))?;
let client: Relayer = Relayer::new(&bitcoin_da_conf).map_err(|e| format!("bitcoin new relayer err: {e}"))?;

Ok(Self { relayer: client, mode: conf.mode })
}
Expand Down
8 changes: 6 additions & 2 deletions crates/node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ use futures::prelude::*;
use madara_runtime::opaque::Block;
use madara_runtime::{self, Hash, RuntimeApi};
use mc_block_proposer::ProposerFactory;
use mc_data_availability::bitcoin::config::BitcoinConfig;
use mc_data_availability::bitcoin::BitcoinClient;
use mc_data_availability::celestia::config::CelestiaConfig;
use mc_data_availability::celestia::CelestiaClient;
use mc_data_availability::ethereum::config::EthereumConfig;
Expand Down Expand Up @@ -415,15 +417,17 @@ pub fn new_full(
DaLayer::Bitcoin => {
let bitcoin_conf = BitcoinConfig::try_from_file(&da_path)?;
let da_client = BitcoinClient::try_from_config(bitcoin_conf.clone())?;
let mode = bitcoin_conf.mode.clone();

task_manager.spawn_essential_handle().spawn(
"da-worker-update",
Some("madara"),
DataAvailabilityWorker::update_state(da_client.clone(), client.clone(), madara_backend.clone()),
DataAvailabilityWorker::update_state(da_client, client.clone(), madara_backend.clone()),
);
task_manager.spawn_essential_handle().spawn(
"da-worker-prove",
Some("madara"),
DataAvailabilityWorker::prove_current_block(da_client.get_mode(), client.clone(), madara_backend),
DataAvailabilityWorker::prove_current_block(mode, client.clone(), madara_backend),
);
}
}
Expand Down
70 changes: 0 additions & 70 deletions crates/pallets/starknet/src/barknet.rs

This file was deleted.

4 changes: 0 additions & 4 deletions crates/pallets/starknet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,6 @@ pub mod pallet {
<Pallet<T>>::store_block(UniqueSaturatedInto::<u64>::unique_saturated_into(
frame_system::Pallet::<T>::block_number(),
));

// Bitcoin-da implementation


}

/// The block is being initialized. Implement to have something happen.
Expand Down
Loading