Skip to content
Open
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
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ hickory-resolver = { version = "0.26", default-features = false }
http = "1.2.0"
itertools = "0.14.0"
jsonrpsee = { version = "0.26.0", features = ["tracing"] }
merkle-cbt = "0.3.2"
parking_lot = "0.12.1"
prost = "0.14.3"
# needs to line up with version required by frost-core
Expand Down
6 changes: 5 additions & 1 deletion app/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,10 @@ impl App {
block connection"
);
}
let coinbase = types::Coinbase {
memo: Vec::new(),
outputs: coinbase,
};
let merkle_root = Body::compute_merkle_root(
&coinbase,
&txs.iter()
Expand All @@ -547,7 +551,7 @@ impl App {
});
(bribe, header, body, tx_fees)
} else {
let coinbase = Vec::new();
let coinbase = types::Coinbase::default();
let merkle_root = Body::compute_merkle_root(&coinbase, &[]);
let body = Body::new(Vec::new(), coinbase);
let header = types::Header {
Expand Down
1 change: 1 addition & 0 deletions app/gui/activity/block_explorer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ impl BlockExplorer {
bincode::serialize(&body).unwrap_or(vec![]).len();
let coinbase_value: bitcoin::Amount = body
.coinbase
.outputs
.iter()
.map(GetBitcoinValue::get_bitcoin_value)
.sum();
Expand Down
4 changes: 2 additions & 2 deletions app/gui/activity/mempool_explorer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ impl MempoolExplorer {
format!("{}", outpoint.txid),
outpoint.vout,
),
OutPoint::Coinbase { merkle_root, vout } => (
OutPoint::Coinbase { txid, vout } => (
"coinbase",
format!("{merkle_root}"),
format!("{txid}"),
*vout,
),
OutPoint::MarketFunds {
Expand Down
8 changes: 4 additions & 4 deletions app/gui/coins/utxo_selector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ pub fn show_utxo(
OutPoint::Deposit(outpoint) => {
("deposit", format!("{}", outpoint.txid), outpoint.vout)
}
OutPoint::Coinbase { merkle_root, vout } => {
("coinbase", format!("{merkle_root}"), *vout)
OutPoint::Coinbase { txid, vout } => {
("coinbase", format!("{txid}"), *vout)
}
OutPoint::MarketFunds {
market_id,
Expand Down Expand Up @@ -250,8 +250,8 @@ pub fn show_unconfirmed_utxo(
OutPoint::Deposit(outpoint) => {
("deposit", format!("{}", outpoint.txid), outpoint.vout)
}
OutPoint::Coinbase { merkle_root, vout } => {
("coinbase", format!("{merkle_root}"), *vout)
OutPoint::Coinbase { txid, vout } => {
("coinbase", format!("{txid}"), *vout)
}
OutPoint::MarketFunds {
market_id,
Expand Down
1 change: 1 addition & 0 deletions lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ itertools = { workspace = true }
jsonrpsee = { workspace = true }
libes = { workspace = true }
libm = "0.2"
merkle-cbt = { workspace = true }
nalgebra = "0.33"
ndarray = "0.15.6"
nonempty = { version = "0.11.0", features = ["serialize"] }
Expand Down
4 changes: 2 additions & 2 deletions lib/archive/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ impl Archive {
if db_version
< Version {
major: 0,
minor: 15,
patch: 1,
minor: 18,
patch: 0,
} =>
{
return Err(Error::IncompatibleVersion {
Expand Down
29 changes: 26 additions & 3 deletions lib/mempool.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use std::collections::{BTreeSet, HashMap, HashSet, VecDeque};
use std::{
collections::{BTreeSet, HashMap, HashSet, VecDeque},
path::PathBuf,
};

use fallible_iterator::FallibleIterator as _;
use futures::{Stream, StreamExt};
Expand Down Expand Up @@ -26,6 +29,12 @@ use crate::{
#[transitive(from(env::error::WriteTxn, EnvError))]
#[transitive(from(rwtxn::error::Commit, RwTxnError))]
pub enum Error {
#[error(
"Incompatible DB version ({}). Please clear the DB (`{}`) and re-sync",
.version,
.db_path.display()
)]
IncompatibleVersion { version: Version, db_path: PathBuf },
#[error(transparent)]
Db(#[from] DbError),
#[error("Database env error")]
Expand Down Expand Up @@ -81,8 +90,22 @@ impl MemPool {
DatabaseUnique::create(env, &mut rwtxn, "trade_order_counter")?;
let version =
DatabaseUnique::create(env, &mut rwtxn, "mempool_version")?;
if version.try_get(&rwtxn, &())?.is_none() {
version.put(&mut rwtxn, &(), &*VERSION)?;
match version.try_get(&rwtxn, &())? {
Some(db_version)
if db_version
< Version {
major: 0,
minor: 18,
patch: 0,
} =>
{
return Err(Error::IncompatibleVersion {
version: db_version,
db_path: env.path().to_path_buf(),
});
}
Some(_) => (),
None => version.put(&mut rwtxn, &(), &*VERSION)?,
}
rwtxn.commit()?;
Ok(Self {
Expand Down
Binary file added lib/net/peer/fixtures/betanet-genesis-response.bin
Binary file not shown.
31 changes: 31 additions & 0 deletions lib/net/peer/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,3 +340,34 @@ mod network_tests {
assert_eq!(magics.len(), EXPECTED.len());
}
}

#[cfg(test)]
mod betanet_capture_tests {
use super::ResponseMessage;
use crate::types::Body;

#[test]
fn betanet_seed_genesis_response_matches_commitments() {
let bytes = include_bytes!("fixtures/betanet-genesis-response.bin");
let response: ResponseMessage = bincode::deserialize(bytes).unwrap();
assert_eq!(bincode::serialize(&response).unwrap(), bytes);
let ResponseMessage::Block { header, mut body } = response else {
panic!("expected block response");
};
assert_eq!(
header.hash().to_string(),
"bcac497706c7552b0bd6791212318ccea83b1d48d1164f54079dc482dc517bfb"
);
assert_eq!(
Body::compute_merkle_root(&body.coinbase, &body.transactions),
header.merkle_root
);
assert!(body.coinbase.memo.is_empty());
assert_eq!(body.coinbase.outputs.len(), 1);
body.coinbase.memo.push(1);
assert_ne!(
Body::compute_merkle_root(&body.coinbase, &body.transactions),
header.merkle_root
);
}
}
12 changes: 6 additions & 6 deletions lib/net/peer/request_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ impl ErrorRx {
enum SourceItem {
Error(error::channel_pool::SendMessage),
Heartbeat(Heartbeat, channel_pool::LimiterGuard<Heartbeat>),
PeerResponse(PeerResponseItem),
Request(Request, channel_pool::LimiterGuard<Request>),
PeerResponse(Box<PeerResponseItem>),
Request(Box<Request>, channel_pool::LimiterGuard<Request>),
}
let (channel_pool, channel_pool_rx) = ChannelPool::new(connection);
let channel_pool_stream = channel_pool_rx
Expand All @@ -59,7 +59,7 @@ impl ErrorRx {
SourceItem::Error(error)
}
futures::future::Either::Right(peer_response) => {
SourceItem::PeerResponse(peer_response)
SourceItem::PeerResponse(Box::new(peer_response))
}
})
.boxed();
Expand Down Expand Up @@ -90,7 +90,7 @@ impl ErrorRx {
.until_n_ready(request_cost(&request))
.await
.unwrap();
SourceItem::Request(request, guard)
SourceItem::Request(Box::new(request), guard)
}
}
})
Expand All @@ -111,13 +111,13 @@ impl ErrorRx {
}
}
SourceItem::Request(request, guard) => {
match channel_pool.send_request(request, guard) {
match channel_pool.send_request(*request, guard) {
Ok(()) => None,
Err(err) => Some(err.into()),
}
}
SourceItem::PeerResponse(peer_response) => {
match peer_response_tx.unbounded_send(peer_response) {
match peer_response_tx.unbounded_send(*peer_response) {
Ok(()) => None,
Err(_err) => {
Some(error::request_queue::Error::PushPeerResponse)
Expand Down
2 changes: 1 addition & 1 deletion lib/node/net_task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1840,7 +1840,7 @@ mod test {

let main_hash = bitcoin::BlockHash::from_byte_array([1; 32]);
let body = Body {
coinbase: Vec::new(),
coinbase: crate::types::Coinbase::default(),
transactions: Vec::new(),
authorizations: Vec::new(),
actor_proofs: Vec::new(),
Expand Down
21 changes: 12 additions & 9 deletions lib/state/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@ pub fn connect_prevalidated(
state
.genesis_timestamp
.put(rwtxn, &(), &mainchain_timestamp)?;
if let Some(first_coinbase) = body.coinbase.first() {
if let Some(first_coinbase) = body.coinbase.outputs.first() {
state.reputation().set_reputation(
rwtxn,
&first_coinbase.address,
Expand Down Expand Up @@ -780,13 +780,13 @@ pub fn connect_prevalidated(
}

crate::validation::BlockValidator::validate_coinbase_outputs(
&body.coinbase,
&body.coinbase.outputs,
height,
)?;

for (vout, output) in body.coinbase.iter().enumerate() {
for (vout, output) in body.coinbase.outputs.iter().enumerate() {
let outpoint = OutPoint::Coinbase {
merkle_root: header.merkle_root,
txid: header.compute_coinbase_txid(),
vout: vout as u32,
};
let filled_content = match output.content.clone() {
Expand Down Expand Up @@ -1209,19 +1209,22 @@ pub fn disconnect_tip(
}

// 6. Revert coinbase UTXOs
body.coinbase.iter().enumerate().rev().try_for_each(
|(vout, _output)| {
body.coinbase
.outputs
.iter()
.enumerate()
.rev()
.try_for_each(|(vout, _output)| {
let outpoint = OutPoint::Coinbase {
merkle_root: header.merkle_root,
txid: header.compute_coinbase_txid(),
vout: vout as u32,
};
if state.delete_utxo(rwtxn, &outpoint)? {
Ok(())
} else {
Err(Error::NoUtxo { outpoint })
}
},
)?;
})?;

// 7. Rollback decision states (Claimed → Voting transitions)
if height > 0 {
Expand Down
10 changes: 9 additions & 1 deletion lib/state/error.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
//! State errors
#![allow(clippy::duplicated_attributes)]

use std::path::PathBuf;

use sneed::{db::error as db, env::error as env, rwtxn::error as rwtxn};
use thiserror::Error;
use transitive::Transitive;

use crate::types::{
AmountOverflowError, AmountUnderflowError, BlockHash, M6id, MerkleRoot,
OutPoint, WithdrawalBundleError,
OutPoint, Version, WithdrawalBundleError,
};

#[derive(Debug, Error)]
Expand Down Expand Up @@ -63,6 +65,12 @@ impl std::error::Error for FillTxOutputContents {}
#[transitive(from(rwtxn::Commit, rwtxn::Error))]
#[transitive(from(rwtxn::Error, sneed::Error))]
pub enum Error {
#[error(
"Incompatible DB version ({}). Please clear the DB (`{}`) and re-sync",
.version,
.db_path.display()
)]
IncompatibleVersion { version: Version, db_path: PathBuf },
#[error(transparent)]
Market(#[from] crate::state::markets::MarketError),
#[error(transparent)]
Expand Down
18 changes: 16 additions & 2 deletions lib/state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,22 @@ impl State {
"withdrawal_bundle_event_blocks",
)?;
let version = DatabaseUnique::create(env, &mut rwtxn, "state_version")?;
if version.try_get(&rwtxn, &())?.is_none() {
version.put(&mut rwtxn, &(), &*VERSION)?;
match version.try_get(&rwtxn, &())? {
Some(db_version)
if db_version
< Version {
major: 0,
minor: 18,
patch: 0,
} =>
{
return Err(Error::IncompatibleVersion {
version: db_version,
db_path: env.path().to_path_buf(),
});
}
Some(_) => (),
None => version.put(&mut rwtxn, &(), &*VERSION)?,
}
let settlement_undo =
DatabaseUnique::create(env, &mut rwtxn, "settlement_undo")?;
Expand Down
2 changes: 1 addition & 1 deletion lib/state/two_way_peg_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1377,7 +1377,7 @@ mod tests {
BatchVerificationContext::new(&mut rand::rng());

let empty_body = Body {
coinbase: Vec::new(),
coinbase: crate::types::Coinbase::default(),
transactions: Vec::new(),
authorizations: Vec::new(),
actor_proofs: Vec::new(),
Expand Down
Loading
Loading