Skip to content

Commit

Permalink
update heed + other deps
Browse files Browse the repository at this point in the history
  • Loading branch information
Ash-L2L committed May 14, 2024
1 parent 4b9fdb7 commit 4b15d60
Show file tree
Hide file tree
Showing 10 changed files with 263 additions and 209 deletions.
323 changes: 176 additions & 147 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ members = [
[workspace.package]
authors = [ "Ash Manning <[email protected]>" ]
edition = "2021"
version = "0.8.2"
version = "0.8.3"

[workspace.dependencies.bip300301]
git = "https://github.com/Ash-L2L/bip300301.git"
Expand Down
2 changes: 1 addition & 1 deletion lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ educe = { version = "0.4.23", features = ["Hash"] }
fallible-iterator = "0.3.0"
futures = "0.3.30"
fraction = "0.14.0"
heed = { git = "https://github.com/meilisearch/heed", tag = "v0.12.4", version = "0.12.4" }
heed = "0.20.0"
hex = { version = "0.4.3", features = ["serde"] }
hex-literal = "0.4.1"
itertools = "0.12.0"
Expand Down
19 changes: 11 additions & 8 deletions lib/archive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,20 @@ impl Archive {
pub const NUM_DBS: u32 = 8;

pub fn new(env: &heed::Env) -> Result<Self, Error> {
let mut rwtxn = env.write_txn()?;
let block_hash_to_height =
env.create_database(Some("hash_to_height"))?;
env.create_database(&mut rwtxn, Some("hash_to_height"))?;
let bmm_verifications =
env.create_database(Some("bmm_verifications"))?;
let bodies = env.create_database(Some("bodies"))?;
let deposits = env.create_database(Some("deposits"))?;
let headers = env.create_database(Some("headers"))?;
let main_headers = env.create_database(Some("main_headers"))?;
let total_work = env.create_database(Some("total_work"))?;
env.create_database(&mut rwtxn, Some("bmm_verifications"))?;
let bodies = env.create_database(&mut rwtxn, Some("bodies"))?;
let deposits = env.create_database(&mut rwtxn, Some("deposits"))?;
let headers = env.create_database(&mut rwtxn, Some("headers"))?;
let main_headers =
env.create_database(&mut rwtxn, Some("main_headers"))?;
let total_work = env.create_database(&mut rwtxn, Some("total_work"))?;
let txid_to_inclusions =
env.create_database(Some("txid_to_inclusions"))?;
env.create_database(&mut rwtxn, Some("txid_to_inclusions"))?;
rwtxn.commit()?;
Ok(Self {
block_hash_to_height,
bmm_verifications,
Expand Down
11 changes: 8 additions & 3 deletions lib/mempool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,14 @@ impl MemPool {
pub const NUM_DBS: u32 = 3;

pub fn new(env: &heed::Env) -> Result<Self, Error> {
let transactions = env.create_database(Some("transactions"))?;
let spent_utxos = env.create_database(Some("spent_utxos"))?;
let address_to_txs = env.create_database(Some("address_to_txs"))?;
let mut rwtxn = env.write_txn()?;
let transactions =
env.create_database(&mut rwtxn, Some("transactions"))?;
let spent_utxos =
env.create_database(&mut rwtxn, Some("spent_utxos"))?;
let address_to_txs =
env.create_database(&mut rwtxn, Some("address_to_txs"))?;
rwtxn.commit()?;
Ok(Self {
transactions,
spent_utxos,
Expand Down
9 changes: 6 additions & 3 deletions lib/net/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::{
use fallible_iterator::{FallibleIterator, IteratorExt};
use futures::{channel::mpsc, StreamExt};
use heed::{
types::{OwnedType, SerdeBincode},
types::{SerdeBincode, Unit},
Database,
};
use parking_lot::RwLock;
Expand Down Expand Up @@ -95,7 +95,7 @@ pub struct Net {
// None indicates that the stream has ended
peer_info_tx:
mpsc::UnboundedSender<(SocketAddr, Option<PeerConnectionInfo>)>,
known_peers: Database<SerdeBincode<SocketAddr>, OwnedType<()>>,
known_peers: Database<SerdeBincode<SocketAddr>, Unit>,
}

impl Net {
Expand Down Expand Up @@ -165,7 +165,10 @@ impl Net {
let (server, _) = make_server_endpoint(bind_addr)?;
let client = make_client_endpoint("0.0.0.0:0".parse()?)?;
let active_peers = Arc::new(RwLock::new(HashMap::new()));
let known_peers = env.create_database(Some("known_peers"))?;
let mut rwtxn = env.write_txn()?;
let known_peers =
env.create_database(&mut rwtxn, Some("known_peers"))?;
rwtxn.commit()?;
let (peer_info_tx, peer_info_rx) = mpsc::unbounded();
let net = Net {
server,
Expand Down
24 changes: 13 additions & 11 deletions lib/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ async fn request_two_way_peg_data(
}

async fn connect_tip_(
rwtxn: &mut RwTxn<'_, '_>,
rwtxn: &mut RwTxn<'_>,
archive: &Archive,
drivechain: &bip300301::Drivechain,
mempool: &MemPool,
Expand Down Expand Up @@ -278,7 +278,7 @@ async fn connect_tip_(
}

async fn disconnect_tip_(
rwtxn: &mut RwTxn<'_, '_>,
rwtxn: &mut RwTxn<'_>,
archive: &Archive,
drivechain: &bip300301::Drivechain,
mempool: &MemPool,
Expand Down Expand Up @@ -818,15 +818,17 @@ impl Node {
let env_path = datadir.join("data.mdb");
// let _ = std::fs::remove_dir_all(&env_path);
std::fs::create_dir_all(&env_path)?;
let env = heed::EnvOpenOptions::new()
.map_size(10 * 1024 * 1024) // 10MB
.max_dbs(
State::NUM_DBS
+ Archive::NUM_DBS
+ MemPool::NUM_DBS
+ Net::NUM_DBS,
)
.open(env_path)?;
let env = unsafe {
heed::EnvOpenOptions::new()
.map_size(1024 * 1024 * 1024) // 1GB
.max_dbs(
State::NUM_DBS
+ Archive::NUM_DBS
+ MemPool::NUM_DBS
+ Net::NUM_DBS,
)
.open(env_path)?
};
let archive = Archive::new(&env)?;
let drivechain = bip300301::Drivechain::new(
THIS_SIDECHAIN,
Expand Down
30 changes: 17 additions & 13 deletions lib/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1052,24 +1052,28 @@ impl State {
pub const WITHDRAWAL_BUNDLE_FAILURE_GAP: u32 = 5;

pub fn new(env: &heed::Env) -> Result<Self, Error> {
let tip = env.create_database(Some("tip"))?;
let height = env.create_database(Some("height"))?;
let amm_pools = env.create_database(Some("amm_pools"))?;
let mut rwtxn = env.write_txn()?;
let tip = env.create_database(&mut rwtxn, Some("tip"))?;
let height = env.create_database(&mut rwtxn, Some("height"))?;
let amm_pools = env.create_database(&mut rwtxn, Some("amm_pools"))?;
let bitasset_reservations =
env.create_database(Some("bitasset_reservations"))?;
env.create_database(&mut rwtxn, Some("bitasset_reservations"))?;
let bitasset_seq_to_bitasset =
env.create_database(Some("bitasset_seq_to_bitasset"))?;
env.create_database(&mut rwtxn, Some("bitasset_seq_to_bitasset"))?;
let bitasset_to_bitasset_seq =
env.create_database(Some("bitasset_to_bitasset_seq"))?;
let bitassets = env.create_database(Some("bitassets"))?;
let dutch_auctions = env.create_database(Some("dutch_auctions"))?;
let utxos = env.create_database(Some("utxos"))?;
let stxos = env.create_database(Some("stxos"))?;
env.create_database(&mut rwtxn, Some("bitasset_to_bitasset_seq"))?;
let bitassets = env.create_database(&mut rwtxn, Some("bitassets"))?;
let dutch_auctions =
env.create_database(&mut rwtxn, Some("dutch_auctions"))?;
let utxos = env.create_database(&mut rwtxn, Some("utxos"))?;
let stxos = env.create_database(&mut rwtxn, Some("stxos"))?;
let pending_withdrawal_bundle =
env.create_database(Some("pending_withdrawal_bundle"))?;
env.create_database(&mut rwtxn, Some("pending_withdrawal_bundle"))?;
let withdrawal_bundles =
env.create_database(Some("withdrawal_bundles"))?;
let deposit_blocks = env.create_database(Some("deposit_blocks"))?;
env.create_database(&mut rwtxn, Some("withdrawal_bundles"))?;
let deposit_blocks =
env.create_database(&mut rwtxn, Some("deposit_blocks"))?;
rwtxn.commit()?;
Ok(Self {
tip,
height,
Expand Down
3 changes: 0 additions & 3 deletions lib/types/hashes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use std::str::FromStr;
use bip300301::bitcoin;
use bitcoin::hashes::Hash as _;
use borsh::{BorshDeserialize, BorshSerialize};
use heed::zerocopy::{self, AsBytes, FromBytes};
use hex::FromHex;
use serde::{Deserialize, Serialize};
use thiserror::Error;
Expand Down Expand Up @@ -132,15 +131,13 @@ impl std::fmt::Debug for MerkleRoot {
}

#[derive(
AsBytes,
BorshDeserialize,
BorshSerialize,
Clone,
Copy,
Default,
Deserialize,
Eq,
FromBytes,
Hash,
Ord,
PartialEq,
Expand Down
49 changes: 30 additions & 19 deletions lib/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use bip300301::bitcoin;
use byteorder::{BigEndian, ByteOrder};
use ed25519_dalek_bip32::{ChildIndex, DerivationPath, ExtendedSigningKey};
use heed::{
types::{OwnedType, SerdeBincode, Str},
types::{Bytes, SerdeBincode, Str, U8},
Database, RoTxn,
};

Expand Down Expand Up @@ -53,10 +53,14 @@ pub enum Error {
#[derive(Clone)]
pub struct Wallet {
env: heed::Env,
// Seed is always [u8; 64], but due to serde not implementing serialize
// for [T; 64], use heed's `Bytes`
// FIXME: Don't store the seed in plaintext.
seed: Database<OwnedType<u8>, OwnedType<[u8; 64]>>,
pub address_to_index: Database<SerdeBincode<Address>, OwnedType<[u8; 4]>>,
pub index_to_address: Database<OwnedType<[u8; 4]>, SerdeBincode<Address>>,
seed: Database<U8, Bytes>,
pub address_to_index:
Database<SerdeBincode<Address>, SerdeBincode<[u8; 4]>>,
pub index_to_address:
Database<SerdeBincode<[u8; 4]>, SerdeBincode<Address>>,
pub unconfirmed_utxos:
Database<SerdeBincode<OutPoint>, SerdeBincode<Output>>,
pub utxos: Database<SerdeBincode<OutPoint>, SerdeBincode<FilledOutput>>,
Expand All @@ -66,7 +70,7 @@ pub struct Wallet {
SerdeBincode<SpentOutput<OutputContent>>,
>,
/// Associates reservation commitments with plaintext BitAsset names
pub bitasset_reservations: Database<OwnedType<[u8; 32]>, Str>,
pub bitasset_reservations: Database<SerdeBincode<[u8; 32]>, Str>,
/// Associates BitAssets with plaintext names
pub known_bitassets: Database<SerdeBincode<BitAssetId>, Str>,
}
Expand All @@ -76,22 +80,29 @@ impl Wallet {

pub fn new(path: &Path) -> Result<Self, Error> {
std::fs::create_dir_all(path)?;
let env = heed::EnvOpenOptions::new()
.map_size(10 * 1024 * 1024) // 10MB
.max_dbs(Self::NUM_DBS)
.open(path)?;
let seed_db = env.create_database(Some("seed"))?;
let address_to_index = env.create_database(Some("address_to_index"))?;
let index_to_address = env.create_database(Some("index_to_address"))?;
let env = unsafe {
heed::EnvOpenOptions::new()
.map_size(10 * 1024 * 1024) // 10MB
.max_dbs(Self::NUM_DBS)
.open(path)?
};
let mut rwtxn = env.write_txn()?;
let seed_db = env.create_database(&mut rwtxn, Some("seed"))?;
let address_to_index =
env.create_database(&mut rwtxn, Some("address_to_index"))?;
let index_to_address =
env.create_database(&mut rwtxn, Some("index_to_address"))?;
let unconfirmed_utxos =
env.create_database(Some("unconfirmed_utxos"))?;
let utxos = env.create_database(Some("utxos"))?;
let stxos = env.create_database(Some("stxos"))?;
env.create_database(&mut rwtxn, Some("unconfirmed_utxos"))?;
let utxos = env.create_database(&mut rwtxn, Some("utxos"))?;
let stxos = env.create_database(&mut rwtxn, Some("stxos"))?;
let spent_unconfirmed_utxos =
env.create_database(Some("spent_unconfirmed_utxos"))?;
env.create_database(&mut rwtxn, Some("spent_unconfirmed_utxos"))?;
let bitasset_reservations =
env.create_database(Some("bitasset_reservations"))?;
let known_bitassets = env.create_database(Some("known_bitassets"))?;
env.create_database(&mut rwtxn, Some("bitasset_reservations"))?;
let known_bitassets =
env.create_database(&mut rwtxn, Some("known_bitassets"))?;
rwtxn.commit()?;
Ok(Self {
env,
seed: seed_db,
Expand All @@ -112,7 +123,7 @@ impl Wallet {
index: u32,
) -> Result<ed25519_dalek::SigningKey, Error> {
let seed = self.seed.get(txn, &0)?.ok_or(Error::NoSeed)?;
let xpriv = ExtendedSigningKey::from_seed(&seed)?;
let xpriv = ExtendedSigningKey::from_seed(seed)?;
let derivation_path = DerivationPath::new([
ChildIndex::Hardened(1),
ChildIndex::Hardened(0),
Expand Down

0 comments on commit 4b15d60

Please sign in to comment.