Skip to content

Commit c366438

Browse files
committed
Explicitly version storage
1 parent b72a3c7 commit c366438

File tree

5 files changed

+54
-15
lines changed

5 files changed

+54
-15
lines changed

lib/archive.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ use fallible_iterator::{FallibleIterator, IteratorExt};
88
use heed::types::SerdeBincode;
99
use sneed::{
1010
db::{self, error::Error as DbError},
11-
env, rwtxn, DatabaseUnique, EnvError, RoTxn, RwTxn, RwTxnError,
11+
env, rwtxn, DatabaseUnique, EnvError, RoTxn, RwTxn, RwTxnError, UnitKey,
1212
};
1313

1414
use crate::types::{
1515
proto::mainchain::{self, Deposit},
16-
Block, BlockHash, BmmResult, Body, Header, Tip, Txid,
16+
Block, BlockHash, BmmResult, Body, Header, Tip, Txid, Version, VERSION,
1717
};
1818

1919
#[derive(thiserror::Error, transitive::Transitive, Debug)]
@@ -146,10 +146,11 @@ pub struct Archive {
146146
SerdeBincode<Txid>,
147147
SerdeBincode<BTreeMap<BlockHash, u32>>,
148148
>,
149+
_version: DatabaseUnique<UnitKey, SerdeBincode<Version>>,
149150
}
150151

151152
impl Archive {
152-
pub const NUM_DBS: u32 = 14;
153+
pub const NUM_DBS: u32 = 15;
153154

154155
pub fn new(env: &sneed::Env) -> Result<Self, Error> {
155156
let mut rwtxn = env.write_txn()?;
@@ -201,6 +202,11 @@ impl Archive {
201202
let total_work = DatabaseUnique::create(env, &mut rwtxn, "total_work")?;
202203
let txid_to_inclusions =
203204
DatabaseUnique::create(env, &mut rwtxn, "txid_to_inclusions")?;
205+
let version =
206+
DatabaseUnique::create(env, &mut rwtxn, "archive_version")?;
207+
if version.try_get(&rwtxn, &())?.is_none() {
208+
version.put(&mut rwtxn, &(), &*VERSION)?;
209+
}
204210
rwtxn.commit()?;
205211
Ok(Self {
206212
block_hash_to_height,
@@ -217,6 +223,7 @@ impl Archive {
217223
successors,
218224
total_work,
219225
txid_to_inclusions,
226+
_version: version,
220227
})
221228
}
222229

lib/mempool.rs

+12-3
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ use std::collections::{HashMap, HashSet, VecDeque};
33
use fallible_iterator::FallibleIterator as _;
44
use heed::types::SerdeBincode;
55
use sneed::{
6-
db, env, rwtxn, DatabaseUnique, DbError, EnvError, RoTxn, RwTxn, RwTxnError,
6+
db, env, rwtxn, DatabaseUnique, DbError, EnvError, RoTxn, RwTxn,
7+
RwTxnError, UnitKey,
78
};
89

910
use crate::types::{
10-
Address, AuthorizedTransaction, InPoint, OutPoint, Output, Txid,
11+
Address, AuthorizedTransaction, InPoint, OutPoint, Output, Txid, Version,
12+
VERSION,
1113
};
1214

1315
#[derive(thiserror::Error, transitive::Transitive, Debug)]
@@ -39,10 +41,11 @@ pub struct MemPool {
3941
/// Associates relevant txs to each address
4042
address_to_txs:
4143
DatabaseUnique<SerdeBincode<Address>, SerdeBincode<HashSet<Txid>>>,
44+
_version: DatabaseUnique<UnitKey, SerdeBincode<Version>>,
4245
}
4346

4447
impl MemPool {
45-
pub const NUM_DBS: u32 = 3;
48+
pub const NUM_DBS: u32 = 4;
4649

4750
pub fn new(env: &sneed::Env) -> Result<Self, Error> {
4851
let mut rwtxn = env.write_txn()?;
@@ -52,11 +55,17 @@ impl MemPool {
5255
DatabaseUnique::create(env, &mut rwtxn, "spent_utxos")?;
5356
let address_to_txs =
5457
DatabaseUnique::create(env, &mut rwtxn, "address_to_txs")?;
58+
let version =
59+
DatabaseUnique::create(env, &mut rwtxn, "mempool_version")?;
60+
if version.try_get(&rwtxn, &())?.is_none() {
61+
version.put(&mut rwtxn, &(), &*VERSION)?;
62+
}
5563
rwtxn.commit()?;
5664
Ok(Self {
5765
transactions,
5866
spent_utxos,
5967
address_to_txs,
68+
_version: version,
6069
})
6170
}
6271

lib/net/mod.rs

+12-3
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,16 @@ use futures::{channel::mpsc, StreamExt};
99
use heed::types::{SerdeBincode, Unit};
1010
use parking_lot::RwLock;
1111
use quinn::{ClientConfig, Endpoint, ServerConfig};
12-
use sneed::{db, env, rwtxn, DatabaseUnique, DbError, EnvError, RwTxnError};
12+
use sneed::{
13+
db, env, rwtxn, DatabaseUnique, DbError, EnvError, RwTxnError, UnitKey,
14+
};
1315
use tokio_stream::StreamNotifyClose;
1416
use tracing::instrument;
1517

1618
use crate::{
1719
archive::Archive,
1820
state::State,
19-
types::{AuthorizedTransaction, Network, THIS_SIDECHAIN},
21+
types::{AuthorizedTransaction, Network, Version, THIS_SIDECHAIN, VERSION},
2022
};
2123

2224
mod peer;
@@ -33,6 +35,7 @@ pub use peer::{
3335

3436
#[derive(thiserror::Error, transitive::Transitive, Debug)]
3537
#[transitive(from(db::error::Put))]
38+
#[transitive(from(db::error::TryGet))]
3639
#[transitive(from(env::error::CreateDb))]
3740
#[transitive(from(env::error::OpenDb))]
3841
#[transitive(from(env::error::WriteTxn))]
@@ -221,10 +224,11 @@ pub struct Net {
221224
peer_info_tx:
222225
mpsc::UnboundedSender<(SocketAddr, Option<PeerConnectionInfo>)>,
223226
known_peers: DatabaseUnique<SerdeBincode<SocketAddr>, Unit>,
227+
_version: DatabaseUnique<UnitKey, SerdeBincode<Version>>,
224228
}
225229

226230
impl Net {
227-
pub const NUM_DBS: u32 = 1;
231+
pub const NUM_DBS: u32 = 2;
228232

229233
fn add_active_peer(
230234
&self,
@@ -335,6 +339,10 @@ impl Net {
335339
known_peers
336340
}
337341
};
342+
let version = DatabaseUnique::create(env, &mut rwtxn, "net_version")?;
343+
if version.try_get(&rwtxn, &())?.is_none() {
344+
version.put(&mut rwtxn, &(), &*VERSION)?;
345+
}
338346
rwtxn.commit()?;
339347
let (peer_info_tx, peer_info_rx) = mpsc::unbounded();
340348
let net = Net {
@@ -344,6 +352,7 @@ impl Net {
344352
active_peers,
345353
peer_info_tx,
346354
known_peers,
355+
_version: version,
347356
};
348357
#[allow(clippy::let_and_return)]
349358
let known_peers: Vec<_> = {

lib/state/mod.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ use crate::{
1414
Authorized, AuthorizedTransaction, BitAssetId, BlockHash, Body,
1515
FilledOutput, FilledTransaction, GetAddress as _, GetBitcoinValue as _,
1616
Header, InPoint, M6id, OutPoint, SpentOutput, Transaction, TxData,
17-
Verify as _, WithdrawalBundle, WithdrawalBundleStatus,
17+
Verify as _, Version, WithdrawalBundle, WithdrawalBundleStatus,
18+
VERSION,
1819
},
1920
util::Watchable,
2021
};
@@ -99,10 +100,11 @@ pub struct State {
99100
SerdeBincode<u32>,
100101
SerdeBincode<(bitcoin::BlockHash, u32)>,
101102
>,
103+
_version: DatabaseUnique<UnitKey, SerdeBincode<Version>>,
102104
}
103105

104106
impl State {
105-
pub const NUM_DBS: u32 = bitassets::Dbs::NUM_DBS + 11;
107+
pub const NUM_DBS: u32 = bitassets::Dbs::NUM_DBS + 12;
106108

107109
pub fn new(env: &sneed::Env) -> Result<Self, Error> {
108110
let mut rwtxn = env.write_txn()?;
@@ -133,6 +135,10 @@ impl State {
133135
&mut rwtxn,
134136
"withdrawal_bundle_event_blocks",
135137
)?;
138+
let version = DatabaseUnique::create(env, &mut rwtxn, "state_version")?;
139+
if version.try_get(&rwtxn, &())?.is_none() {
140+
version.put(&mut rwtxn, &(), &*VERSION)?;
141+
}
136142
rwtxn.commit()?;
137143
Ok(Self {
138144
tip,
@@ -147,6 +153,7 @@ impl State {
147153
withdrawal_bundles,
148154
withdrawal_bundle_event_blocks,
149155
deposit_blocks,
156+
_version: version,
150157
})
151158
}
152159

lib/wallet.rs

+11-4
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use heed::{
1515
types::{Bytes, SerdeBincode, Str, U32, U8},
1616
};
1717
use serde::{Deserialize, Serialize};
18-
use sneed::{db, env, rwtxn, DbError, Env, EnvError, RwTxnError};
18+
use sneed::{db, env, rwtxn, DbError, Env, EnvError, RwTxnError, UnitKey};
1919
use thiserror::Error;
2020
use tokio_stream::{wrappers::WatchStream, StreamMap};
2121

@@ -26,8 +26,8 @@ use crate::{
2626
AuthorizedTransaction, BitAssetData, BitAssetId, BitcoinOutputContent,
2727
DutchAuctionId, DutchAuctionParams, EncryptionPubKey, FilledOutput,
2828
GetBitcoinValue, Hash, InPoint, OutPoint, Output, OutputContent,
29-
SpentOutput, Transaction, TxData, VerifyingKey,
30-
WithdrawalOutputContent,
29+
SpentOutput, Transaction, TxData, VerifyingKey, Version,
30+
WithdrawalOutputContent, VERSION,
3131
},
3232
util::Watchable,
3333
};
@@ -144,10 +144,11 @@ pub struct Wallet {
144144
known_bitassets: DatabaseUnique<SerdeBincode<BitAssetId>, Str>,
145145
/// Map each verifying key to it's index
146146
vk_to_index: DatabaseUnique<SerdeBincode<VerifyingKey>, U32<BigEndian>>,
147+
_version: DatabaseUnique<UnitKey, SerdeBincode<Version>>,
147148
}
148149

149150
impl Wallet {
150-
pub const NUM_DBS: u32 = 13;
151+
pub const NUM_DBS: u32 = 14;
151152

152153
pub fn new(path: &Path) -> Result<Self, Error> {
153154
std::fs::create_dir_all(path)?;
@@ -185,6 +186,10 @@ impl Wallet {
185186
DatabaseUnique::create(&env, &mut rwtxn, "known_bitassets")?;
186187
let vk_to_index =
187188
DatabaseUnique::create(&env, &mut rwtxn, "vk_to_index")?;
189+
let version = DatabaseUnique::create(&env, &mut rwtxn, "version")?;
190+
if version.try_get(&rwtxn, &())?.is_none() {
191+
version.put(&mut rwtxn, &(), &*VERSION)?;
192+
}
188193
rwtxn.commit()?;
189194
Ok(Self {
190195
env,
@@ -201,6 +206,7 @@ impl Wallet {
201206
bitasset_reservations,
202207
known_bitassets,
203208
vk_to_index,
209+
_version: version,
204210
})
205211
}
206212

@@ -1494,6 +1500,7 @@ impl Watchable<()> for Wallet {
14941500
bitasset_reservations,
14951501
known_bitassets,
14961502
vk_to_index,
1503+
_version: _,
14971504
} = self;
14981505
let watchables = [
14991506
seed.watch().clone(),

0 commit comments

Comments
 (0)