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

[RK] upstream merge dev-v0.3.17 #29

Open
wants to merge 9 commits into
base: dev-0.3.17
Choose a base branch
from
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ analyzer-target
testing/integration/perflogs*
Servers.toml
release
Cargo.lock
116 changes: 57 additions & 59 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ members = [
]

[workspace.package]
rust-version = "1.82.0"
version = "0.3.16"
rust-version = "1.83.0"
version = "0.3.17"
authors = ["Spectre developers"]
license = "ISC"
repository = "https://github.com/spectre-project/rusty-spectre"
Expand All @@ -80,61 +80,61 @@ include = [
]

[workspace.dependencies]
# spectre-testing-integration = { version = "0.3.16", path = "testing/integration" }
spectre-addresses = { version = "0.3.16", path = "crypto/addresses" }
spectre-addressmanager = { version = "0.3.16", path = "components/addressmanager" }
spectre-bip32 = { version = "0.3.16", path = "wallet/bip32" }
spectre-cli = { version = "0.3.16", path = "cli" }
spectre-connectionmanager = { version = "0.3.16", path = "components/connectionmanager" }
spectre-consensus = { version = "0.3.16", path = "consensus" }
spectre-consensus-core = { version = "0.3.16", path = "consensus/core" }
spectre-consensus-client = { version = "0.3.16", path = "consensus/client" }
spectre-consensus-notify = { version = "0.3.16", path = "consensus/notify" }
spectre-consensus-wasm = { version = "0.3.16", path = "consensus/wasm" }
spectre-consensusmanager = { version = "0.3.16", path = "components/consensusmanager" }
spectre-core = { version = "0.3.16", path = "core" }
spectre-daemon = { version = "0.3.16", path = "daemon" }
spectre-database = { version = "0.3.16", path = "database" }
spectre-grpc-client = { version = "0.3.16", path = "rpc/grpc/client" }
spectre-grpc-core = { version = "0.3.16", path = "rpc/grpc/core" }
spectre-grpc-server = { version = "0.3.16", path = "rpc/grpc/server" }
spectre-hashes = { version = "0.3.16", path = "crypto/hashes" }
spectre-index-core = { version = "0.3.16", path = "indexes/core" }
spectre-index-processor = { version = "0.3.16", path = "indexes/processor" }
spectre-math = { version = "0.3.16", path = "math" }
spectre-merkle = { version = "0.3.16", path = "crypto/merkle" }
spectre-metrics-core = { version = "0.3.16", path = "metrics/core" }
spectre-mining = { version = "0.3.16", path = "mining" }
spectre-mining-errors = { version = "0.3.16", path = "mining/errors" }
spectre-muhash = { version = "0.3.16", path = "crypto/muhash" }
spectre-notify = { version = "0.3.16", path = "notify" }
spectre-p2p-flows = { version = "0.3.16", path = "protocol/flows" }
spectre-p2p-lib = { version = "0.3.16", path = "protocol/p2p" }
spectre-perf-monitor = { version = "0.3.16", path = "metrics/perf_monitor" }
spectre-pow = { version = "0.3.16", path = "consensus/pow" }
spectre-rpc-core = { version = "0.3.16", path = "rpc/core" }
spectre-rpc-macros = { version = "0.3.16", path = "rpc/macros" }
spectre-rpc-service = { version = "0.3.16", path = "rpc/service" }
spectre-txscript = { version = "0.3.16", path = "crypto/txscript" }
spectre-txscript-errors = { version = "0.3.16", path = "crypto/txscript/errors" }
spectre-utils = { version = "0.3.16", path = "utils" }
spectre-utils-tower = { version = "0.3.16", path = "utils/tower" }
spectre-utxoindex = { version = "0.3.16", path = "indexes/utxoindex" }
spectre-wallet = { version = "0.3.16", path = "wallet/native" }
spectre-wallet-cli-wasm = { version = "0.3.16", path = "wallet/wasm" }
spectre-wallet-keys = { version = "0.3.16", path = "wallet/keys" }
spectre-wallet-psst = { version = "0.3.16", path = "wallet/psst" }
spectre-wallet-core = { version = "0.3.16", path = "wallet/core" }
spectre-wallet-macros = { version = "0.3.16", path = "wallet/macros" }
spectre-wasm = { version = "0.3.16", path = "wasm" }
spectre-wasm-core = { version = "0.3.16", path = "wasm/core" }
spectre-wrpc-client = { version = "0.3.16", path = "rpc/wrpc/client" }
spectre-wrpc-proxy = { version = "0.3.16", path = "rpc/wrpc/proxy" }
spectre-wrpc-server = { version = "0.3.16", path = "rpc/wrpc/server" }
spectre-wrpc-wasm = { version = "0.3.16", path = "rpc/wrpc/wasm" }
spectre-wrpc-example-subscriber = { version = "0.3.16", path = "rpc/wrpc/examples/subscriber" }
spectred = { version = "0.3.16", path = "spectred" }
spectre-alloc = { version = "0.3.16", path = "utils/alloc" }
# spectre-testing-integration = { version = "0.3.17", path = "testing/integration" }
spectre-addresses = { version = "0.3.17", path = "crypto/addresses" }
spectre-addressmanager = { version = "0.3.17", path = "components/addressmanager" }
spectre-bip32 = { version = "0.3.17", path = "wallet/bip32" }
spectre-cli = { version = "0.3.17", path = "cli" }
spectre-connectionmanager = { version = "0.3.17", path = "components/connectionmanager" }
spectre-consensus = { version = "0.3.17", path = "consensus" }
spectre-consensus-core = { version = "0.3.17", path = "consensus/core" }
spectre-consensus-client = { version = "0.3.17", path = "consensus/client" }
spectre-consensus-notify = { version = "0.3.17", path = "consensus/notify" }
spectre-consensus-wasm = { version = "0.3.17", path = "consensus/wasm" }
spectre-consensusmanager = { version = "0.3.17", path = "components/consensusmanager" }
spectre-core = { version = "0.3.17", path = "core" }
spectre-daemon = { version = "0.3.17", path = "daemon" }
spectre-database = { version = "0.3.17", path = "database" }
spectre-grpc-client = { version = "0.3.17", path = "rpc/grpc/client" }
spectre-grpc-core = { version = "0.3.17", path = "rpc/grpc/core" }
spectre-grpc-server = { version = "0.3.17", path = "rpc/grpc/server" }
spectre-hashes = { version = "0.3.17", path = "crypto/hashes" }
spectre-index-core = { version = "0.3.17", path = "indexes/core" }
spectre-index-processor = { version = "0.3.17", path = "indexes/processor" }
spectre-math = { version = "0.3.17", path = "math" }
spectre-merkle = { version = "0.3.17", path = "crypto/merkle" }
spectre-metrics-core = { version = "0.3.17", path = "metrics/core" }
spectre-mining = { version = "0.3.17", path = "mining" }
spectre-mining-errors = { version = "0.3.17", path = "mining/errors" }
spectre-muhash = { version = "0.3.17", path = "crypto/muhash" }
spectre-notify = { version = "0.3.17", path = "notify" }
spectre-p2p-flows = { version = "0.3.17", path = "protocol/flows" }
spectre-p2p-lib = { version = "0.3.17", path = "protocol/p2p" }
spectre-perf-monitor = { version = "0.3.17", path = "metrics/perf_monitor" }
spectre-pow = { version = "0.3.17", path = "consensus/pow" }
spectre-rpc-core = { version = "0.3.17", path = "rpc/core" }
spectre-rpc-macros = { version = "0.3.17", path = "rpc/macros" }
spectre-rpc-service = { version = "0.3.17", path = "rpc/service" }
spectre-txscript = { version = "0.3.17", path = "crypto/txscript" }
spectre-txscript-errors = { version = "0.3.17", path = "crypto/txscript/errors" }
spectre-utils = { version = "0.3.17", path = "utils" }
spectre-utils-tower = { version = "0.3.17", path = "utils/tower" }
spectre-utxoindex = { version = "0.3.17", path = "indexes/utxoindex" }
spectre-wallet = { version = "0.3.17", path = "wallet/native" }
spectre-wallet-cli-wasm = { version = "0.3.17", path = "wallet/wasm" }
spectre-wallet-keys = { version = "0.3.17", path = "wallet/keys" }
spectre-wallet-psst = { version = "0.3.17", path = "wallet/psst" }
spectre-wallet-core = { version = "0.3.17", path = "wallet/core" }
spectre-wallet-macros = { version = "0.3.17", path = "wallet/macros" }
spectre-wasm = { version = "0.3.17", path = "wasm" }
spectre-wasm-core = { version = "0.3.17", path = "wasm/core" }
spectre-wrpc-client = { version = "0.3.17", path = "rpc/wrpc/client" }
spectre-wrpc-proxy = { version = "0.3.17", path = "rpc/wrpc/proxy" }
spectre-wrpc-server = { version = "0.3.17", path = "rpc/wrpc/server" }
spectre-wrpc-wasm = { version = "0.3.17", path = "rpc/wrpc/wasm" }
spectre-wrpc-example-subscriber = { version = "0.3.17", path = "rpc/wrpc/examples/subscriber" }
spectred = { version = "0.3.17", path = "spectred" }
spectre-alloc = { version = "0.3.17", path = "utils/alloc" }

# external
aes = "0.8.3"
Expand Down Expand Up @@ -245,8 +245,6 @@ slugify-rs = "0.0.3"
smallvec = { version = "1.11.1", features = ["serde"] }
sorted-insert = "0.2.3"
spectrex = ">=0.3.17"
statest = "0.2.2"
statrs = "0.13.0" # TODO "0.16.0"
subtle = { version = "2.5.0", default-features = false }
sysinfo = "0.31.2"
tempfile = "3.8.1"
Expand Down
10 changes: 1 addition & 9 deletions cli/src/modules/history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,7 @@ impl History {
};

let length = ids.size_hint().0;
let skip = if let Some(last) = last {
if last > length {
0
} else {
length - last
}
} else {
0
};
let skip = if let Some(last) = last { length.saturating_sub(last) } else { 0 };
let mut index = 0;
let page = 25;

Expand Down
2 changes: 1 addition & 1 deletion consensus/client/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ impl Header {

impl TryCastFromJs for Header {
type Error = Error;
fn try_cast_from<'a, R>(value: &'a R) -> Result<Cast<Self>, Self::Error>
fn try_cast_from<'a, R>(value: &'a R) -> Result<Cast<'a, Self>, Self::Error>
where
R: AsRef<JsValue> + 'a,
{
Expand Down
2 changes: 1 addition & 1 deletion consensus/client/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ impl AsRef<TransactionInput> for TransactionInput {

impl TryCastFromJs for TransactionInput {
type Error = Error;
fn try_cast_from<'a, R>(value: &'a R) -> std::result::Result<Cast<Self>, Self::Error>
fn try_cast_from<'a, R>(value: &'a R) -> std::result::Result<Cast<'a, Self>, Self::Error>
where
R: AsRef<JsValue> + 'a,
{
Expand Down
2 changes: 1 addition & 1 deletion consensus/client/src/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ impl From<&TransactionOutput> for cctx::TransactionOutput {

impl TryCastFromJs for TransactionOutput {
type Error = Error;
fn try_cast_from<'a, R>(value: &'a R) -> std::result::Result<Cast<Self>, Self::Error>
fn try_cast_from<'a, R>(value: &'a R) -> std::result::Result<Cast<'a, Self>, Self::Error>
where
R: AsRef<JsValue> + 'a,
{
Expand Down
2 changes: 1 addition & 1 deletion consensus/client/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ impl Transaction {

impl TryCastFromJs for Transaction {
type Error = Error;
fn try_cast_from<'a, R>(value: &'a R) -> std::result::Result<Cast<Self>, Self::Error>
fn try_cast_from<'a, R>(value: &'a R) -> std::result::Result<Cast<'a, Self>, Self::Error>
where
R: AsRef<JsValue> + 'a,
{
Expand Down
4 changes: 2 additions & 2 deletions consensus/client/src/utxo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ impl TryIntoUtxoEntryReferences for JsValue {

impl TryCastFromJs for UtxoEntry {
type Error = Error;
fn try_cast_from<'a, R>(value: &'a R) -> Result<Cast<Self>, Self::Error>
fn try_cast_from<'a, R>(value: &'a R) -> Result<Cast<'a, Self>, Self::Error>
where
R: AsRef<JsValue> + 'a,
{
Expand Down Expand Up @@ -405,7 +405,7 @@ impl TryFrom<JsValue> for UtxoEntries {

impl TryCastFromJs for UtxoEntryReference {
type Error = Error;
fn try_cast_from<'a, R>(value: &'a R) -> Result<Cast<Self>, Self::Error>
fn try_cast_from<'a, R>(value: &'a R) -> Result<Cast<'a, Self>, Self::Error>
where
R: AsRef<JsValue> + 'a,
{
Expand Down
4 changes: 2 additions & 2 deletions consensus/core/src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::{
tx::TxResult,
},
header::Header,
pruning::{PruningPointProof, PruningPointTrustedData, PruningPointsList},
pruning::{PruningPointProof, PruningPointTrustedData, PruningPointsList, PruningProofMetadata},
trusted::{ExternalGhostdagData, TrustedBlock},
tx::{MutableTransaction, Transaction, TransactionOutpoint, UtxoEntry},
BlockHashSet, BlueWorkType, ChainPath,
Expand Down Expand Up @@ -203,7 +203,7 @@ pub trait ConsensusApi: Send + Sync {
unimplemented!()
}

fn validate_pruning_proof(&self, proof: &PruningPointProof) -> PruningImportResult<()> {
fn validate_pruning_proof(&self, proof: &PruningPointProof, proof_metadata: &PruningProofMetadata) -> PruningImportResult<()> {
unimplemented!()
}

Expand Down
5 changes: 2 additions & 3 deletions consensus/core/src/config/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub mod consensus {

/// Size of the **sampled** median time window (independent of BPS)
pub const MEDIAN_TIME_SAMPLED_WINDOW_SIZE: u64 =
((2 * NEW_TIMESTAMP_DEVIATION_TOLERANCE - 1) + PAST_MEDIAN_TIME_SAMPLE_INTERVAL - 1) / PAST_MEDIAN_TIME_SAMPLE_INTERVAL;
(2 * NEW_TIMESTAMP_DEVIATION_TOLERANCE - 1).div_ceil(PAST_MEDIAN_TIME_SAMPLE_INTERVAL);

//
// ~~~~~~~~~~~~~~~~~~~~~~~~~ Max difficulty target ~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down Expand Up @@ -71,8 +71,7 @@ pub mod consensus {
pub const DIFFICULTY_WINDOW_SAMPLE_INTERVAL: u64 = 4;

/// Size of the **sampled** difficulty window (independent of BPS)
pub const DIFFICULTY_SAMPLED_WINDOW_SIZE: u64 =
(NEW_DIFFICULTY_WINDOW_DURATION + DIFFICULTY_WINDOW_SAMPLE_INTERVAL - 1) / DIFFICULTY_WINDOW_SAMPLE_INTERVAL;
pub const DIFFICULTY_SAMPLED_WINDOW_SIZE: u64 = NEW_DIFFICULTY_WINDOW_DURATION.div_ceil(DIFFICULTY_WINDOW_SAMPLE_INTERVAL);

//
// ~~~~~~~~~~~~~~~~~~~ Finality & Pruning ~~~~~~~~~~~~~~~~~~~
Expand Down
3 changes: 3 additions & 0 deletions consensus/core/src/errors/pruning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ pub enum PruningImportError {

#[error("process exit was initiated while validating pruning point proof")]
PruningValidationInterrupted,

#[error("block {0} at level {1} has invalid proof of work for level")]
ProofOfWorkFailed(Hash, BlockLevel),
}

pub type PruningImportResult<T> = std::result::Result<T, PruningImportError>;
4 changes: 4 additions & 0 deletions consensus/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ pub mod utxo;
/// overall blocks, so 2^192 is definitely a justified upper-bound.
pub type BlueWorkType = spectre_math::Uint192;

/// The extends directly from the expectation above about having no more than
/// 2^128 work in a single block
pub const MAX_WORK_LEVEL: BlockLevel = 128;

/// The type used to represent the GHOSTDAG K parameter
pub type KType = u16;

Expand Down
4 changes: 2 additions & 2 deletions consensus/core/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ impl Serialize for NetworkId {

struct NetworkIdVisitor;

impl<'de> de::Visitor<'de> for NetworkIdVisitor {
impl de::Visitor<'_> for NetworkIdVisitor {
type Value = NetworkId;

fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
Expand Down Expand Up @@ -413,7 +413,7 @@ impl TryFrom<JsValue> for NetworkId {

impl TryCastFromJs for NetworkId {
type Error = NetworkIdError;
fn try_cast_from<'a, R>(value: &'a R) -> Result<Cast<Self>, Self::Error>
fn try_cast_from<'a, R>(value: &'a R) -> Result<Cast<'a, Self>, Self::Error>
where
R: AsRef<JsValue> + 'a,
{
Expand Down
13 changes: 13 additions & 0 deletions consensus/core/src/pruning.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::{
header::Header,
trusted::{TrustedGhostdagData, TrustedHeader},
BlueWorkType,
};
use spectre_hashes::Hash;
use std::sync::Arc;
Expand All @@ -19,3 +20,15 @@ pub struct PruningPointTrustedData {
/// Union of GHOSTDAG data required to verify blocks in the future of the pruning point
pub ghostdag_blocks: Vec<TrustedGhostdagData>,
}

#[derive(Clone, Copy)]
pub struct PruningProofMetadata {
/// The claimed work of the initial relay block (from the prover)
pub relay_block_blue_work: BlueWorkType,
}

impl PruningProofMetadata {
pub fn new(relay_block_blue_work: BlueWorkType) -> Self {
Self { relay_block_blue_work }
}
}
6 changes: 3 additions & 3 deletions consensus/core/src/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ impl<'a, T: VerifiableTransaction> Iterator for PopulatedInputIterator<'a, T> {
}
}

impl<'a, T: VerifiableTransaction> ExactSizeIterator for PopulatedInputIterator<'a, T> {}
impl<T: VerifiableTransaction> ExactSizeIterator for PopulatedInputIterator<'_, T> {}

/// Represents a read-only referenced transaction along with fully populated UTXO entry data
pub struct PopulatedTransaction<'a> {
Expand All @@ -334,7 +334,7 @@ impl<'a> PopulatedTransaction<'a> {
}
}

impl<'a> VerifiableTransaction for PopulatedTransaction<'a> {
impl VerifiableTransaction for PopulatedTransaction<'_> {
fn tx(&self) -> &Transaction {
self.tx
}
Expand Down Expand Up @@ -362,7 +362,7 @@ impl<'a> ValidatedTransaction<'a> {
}
}

impl<'a> VerifiableTransaction for ValidatedTransaction<'a> {
impl VerifiableTransaction for ValidatedTransaction<'_> {
fn tx(&self) -> &Transaction {
self.tx
}
Expand Down
4 changes: 2 additions & 2 deletions consensus/core/src/tx/script_public_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl Serialize for ScriptPublicKey {
}
}

impl<'de: 'a, 'a> Deserialize<'de> for ScriptPublicKey {
impl<'de> Deserialize<'de> for ScriptPublicKey {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
Expand Down Expand Up @@ -374,7 +374,7 @@ impl BorshDeserialize for ScriptPublicKey {
type CastError = workflow_wasm::error::Error;
impl TryCastFromJs for ScriptPublicKey {
type Error = workflow_wasm::error::Error;
fn try_cast_from<'a, R>(value: &'a R) -> Result<Cast<Self>, Self::Error>
fn try_cast_from<'a, R>(value: &'a R) -> Result<Cast<'a, Self>, Self::Error>
where
R: AsRef<JsValue> + 'a,
{
Expand Down
14 changes: 12 additions & 2 deletions consensus/pow/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,22 @@ impl State {
}

pub fn calc_block_level(header: &Header, max_block_level: BlockLevel) -> BlockLevel {
let (block_level, _) = calc_block_level_check_pow(header, max_block_level);
block_level
}

pub fn calc_block_level_check_pow(header: &Header, max_block_level: BlockLevel) -> (BlockLevel, bool) {
if header.parents_by_level.is_empty() {
return max_block_level; // Genesis has the max block level
return (max_block_level, true); // Genesis has the max block level
}

let state = State::new(header);
let (_, pow) = state.check_pow(header.nonce);
let (passed, pow) = state.check_pow(header.nonce);
let block_level = calc_level_from_pow(pow, max_block_level);
(block_level, passed)
}

pub fn calc_level_from_pow(pow: Uint256, max_block_level: BlockLevel) -> BlockLevel {
let signed_block_level = max_block_level as i64 - pow.bits() as i64;
max(signed_block_level, 0) as BlockLevel
}
Loading
Loading