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

Blockchain: add alt-block handling #260

Merged
merged 33 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
d648871
add new tables & types
Boog900 Aug 29, 2024
e1ae848
add function to fully add an alt block
Boog900 Aug 30, 2024
ed887a7
resolve current todo!s
Boog900 Aug 30, 2024
bc619b6
add new requests
Boog900 Aug 31, 2024
029f439
WIP: starting re-orgs
Boog900 Sep 1, 2024
6927b05
add last service request
Boog900 Sep 5, 2024
21e4b3a
commit Cargo.lock
Boog900 Sep 5, 2024
a9d8eee
Merge branch 'main' into storage-alt-blocks
Boog900 Sep 5, 2024
123aedd
add test
Boog900 Sep 6, 2024
ba5c5ac
more docs + cleanup + alt blocks request
Boog900 Sep 7, 2024
f92375f
clippy + fmt
Boog900 Sep 7, 2024
a864f93
document types
Boog900 Sep 7, 2024
6119972
move tx_fee to helper
Boog900 Sep 8, 2024
b211210
more doc updates
Boog900 Sep 8, 2024
68807e7
fmt
Boog900 Sep 8, 2024
c03065b
fix imports
Boog900 Sep 8, 2024
18d700b
fix fee
Boog900 Sep 9, 2024
28f7605
Apply suggestions from code review
Boog900 Sep 15, 2024
0907454
remove default features from `cuprate-helper`
Boog900 Sep 15, 2024
47fb1a2
review fixes
Boog900 Sep 15, 2024
19117bb
fix find_block
Boog900 Sep 15, 2024
0a95283
add a test and fix some issues in chain history
Boog900 Sep 16, 2024
060e7ca
fix clippy
Boog900 Sep 16, 2024
fb592e3
fmt
Boog900 Sep 16, 2024
6aeb720
Apply suggestions from code review
Boog900 Sep 18, 2024
c4c025a
add dev dep
Boog900 Sep 18, 2024
51aa1b6
cargo update
Boog900 Sep 18, 2024
a92313b
move `flush_alt_blocks`
Boog900 Sep 18, 2024
be3114b
review fixes
Boog900 Sep 18, 2024
4e00cd0
more review fixes
Boog900 Sep 18, 2024
6ee3b16
Merge branch 'main' into storage-alt-blocks
Boog900 Sep 18, 2024
66a82a3
fix clippy
Boog900 Sep 18, 2024
e23a3f6
remove INVARIANT comments
Boog900 Sep 19, 2024
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
1 change: 1 addition & 0 deletions Cargo.lock

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

4 changes: 3 additions & 1 deletion helper/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ repository = "https://github.com/Cuprate/cuprate/tree/main/consensus"


[features]
# TODO: I don't think this is a good idea
Boog900 marked this conversation as resolved.
Show resolved Hide resolved
# All features on by default.
default = ["std", "atomic", "asynch", "cast", "fs", "num", "map", "time", "thread", "constants"]
default = ["std", "atomic", "asynch", "cast", "fs", "num", "map", "time", "thread", "constants", "tx-utils"]
std = []
atomic = ["dep:crossbeam"]
asynch = ["dep:futures", "dep:rayon"]
Expand All @@ -21,6 +22,7 @@ num = []
map = ["cast", "dep:monero-serai"]
time = ["dep:chrono", "std"]
thread = ["std", "dep:target_os_lib"]
tx-utils = ["dep:monero-serai"]
Boog900 marked this conversation as resolved.
Show resolved Hide resolved

[dependencies]
crossbeam = { workspace = true, optional = true }
Expand Down
2 changes: 2 additions & 0 deletions helper/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ pub mod thread;
#[cfg(feature = "time")]
pub mod time;

#[cfg(feature = "tx-utils")]
pub mod tx_utils;
//---------------------------------------------------------------------------------------------------- Private Usage

//----------------------------------------------------------------------------------------------------
34 changes: 34 additions & 0 deletions helper/src/tx_utils.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//! Utils for working with [`Transaction`]
Boog900 marked this conversation as resolved.
Show resolved Hide resolved

use monero_serai::transaction::{Input, Transaction};

/// Calculates the fee of the [`Transaction`].
///
/// # Panics
/// This will panic if the inputs overflow or the transaction outputs too much, so should only
/// be used on known to be valid txs.
pub fn tx_fee(tx: &Transaction) -> u64 {
Boog900 marked this conversation as resolved.
Show resolved Hide resolved
let mut fee = 0_u64;

match &tx {
Transaction::V1 { prefix, .. } => {
for input in &prefix.inputs {
match input {
Input::Gen(_) => return 0,
Input::ToKey { amount, .. } => {
fee = fee.checked_add(amount.unwrap_or(0)).unwrap();
}
}
}

for output in &prefix.outputs {
fee = fee.checked_sub(output.amount.unwrap_or(0)).unwrap();
}
}
Transaction::V2 { proofs, .. } => {
fee = proofs.as_ref().unwrap().base.fee;
}
};

fee
}
3 changes: 2 additions & 1 deletion storage/blockchain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ cuprate-database = { path = "../database" }
cuprate-database-service = { path = "../service" }
cuprate-helper = { path = "../../helper", features = ["fs", "thread", "map"] }
cuprate-types = { path = "../../types", features = ["blockchain"] }
cuprate-pruning = { path = "../../pruning" }

bitflags = { workspace = true, features = ["std", "serde", "bytemuck"] }
bytemuck = { workspace = true, features = ["must_cast", "derive", "min_const_generics", "extern_crate_alloc"] }
curve25519-dalek = { workspace = true }
cuprate-pruning = { path = "../../pruning" }
rand = { workspace = true }
monero-serai = { workspace = true, features = ["std"] }
serde = { workspace = true, optional = true }

Expand Down
Loading
Loading