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 8, 2024
1 parent 6d2915c commit c2008be
Show file tree
Hide file tree
Showing 9 changed files with 264 additions and 203 deletions.
334 changes: 185 additions & 149 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.7.2"
version = "0.7.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 @@ -20,7 +20,7 @@ ed25519-dalek-bip32 = "0.3.0"
educe = { version = "0.4.23", features = ["Hash"] }
fallible-iterator = "0.3.0"
futures = "0.3.30"
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"
jsonrpsee = { version = "0.20.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
8 changes: 6 additions & 2 deletions lib/mempool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@ impl MemPool {
pub const NUM_DBS: u32 = 2;

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 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"))?;
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 @@ -226,7 +226,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 @@ -259,7 +259,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 @@ -799,15 +799,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
24 changes: 13 additions & 11 deletions lib/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,18 +416,21 @@ 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 mut rwtxn = env.write_txn()?;
let tip = env.create_database(&mut rwtxn, Some("tip"))?;
let height = env.create_database(&mut rwtxn, Some("height"))?;
let bitname_reservations =
env.create_database(Some("bitname_reservations"))?;
let bitnames = env.create_database(Some("bitnames"))?;
let utxos = env.create_database(Some("utxos"))?;
let stxos = env.create_database(Some("stxos"))?;
env.create_database(&mut rwtxn, Some("bitname_reservations"))?;
let bitnames = env.create_database(&mut rwtxn, Some("bitnames"))?;
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 Expand Up @@ -1525,8 +1528,7 @@ impl State {
// revert transaction effects
match &tx.data {
None => (),
Some(TxData::BitNameReservation { commitment }) => {
self.bitname_reservations.put(rwtxn, &txid, commitment)?;
Some(TxData::BitNameReservation { .. }) => {
if !self.bitname_reservations.delete(rwtxn, &txid)? {
return Err(Error::MissingReservation { txid });
}
Expand Down
45 changes: 28 additions & 17 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 @@ -52,14 +52,18 @@ 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 utxos: Database<SerdeBincode<OutPoint>, SerdeBincode<FilledOutput>>,
pub stxos: Database<SerdeBincode<OutPoint>, SerdeBincode<SpentOutput>>,
/// associates reservation commitments with plaintext bitnames
pub bitname_reservations: Database<OwnedType<[u8; 32]>, Str>,
pub bitname_reservations: Database<SerdeBincode<[u8; 32]>, Str>,
/// associates bitnames with plaintext names
pub known_bitnames: Database<SerdeBincode<BitName>, Str>,
}
Expand All @@ -69,18 +73,25 @@ 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 utxos = env.create_database(Some("utxos"))?;
let stxos = env.create_database(Some("stxos"))?;
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 utxos = env.create_database(&mut rwtxn, Some("utxos"))?;
let stxos = env.create_database(&mut rwtxn, Some("stxos"))?;
let bitname_reservations =
env.create_database(Some("bitname_reservations"))?;
let known_bitnames = env.create_database(Some("known_bitnames"))?;
env.create_database(&mut rwtxn, Some("bitname_reservations"))?;
let known_bitnames =
env.create_database(&mut rwtxn, Some("known_bitnames"))?;
rwtxn.commit()?;
Ok(Self {
env,
seed: seed_db,
Expand All @@ -99,7 +110,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 c2008be

Please sign in to comment.