Skip to content

Fixes for 2.0.4 #2611

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

Merged
merged 4 commits into from
Mar 19, 2025
Merged
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 config/src/defaults.rs
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,7 @@ pub trait Defaults {
[
(ProtocolVersion::V1_7, (0, 45)),
(ProtocolVersion::V1_8, (3_048_960, 45)),
(ProtocolVersion::V2_0, (3_108_950, 20)),
]
.into_iter()
.collect()
Expand Down
6 changes: 6 additions & 0 deletions data_structures/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,12 @@ pub enum TransactionError {
stake, max_stake
)]
StakeAboveMaximum { max_stake: u64, stake: u64 },
/// Stake weight limit exceeded
#[fail(
display = "Stake Transaction weight ({}) exceeds the limit ({})",
weight, max_weight
)]
StakeWeightLimitExceeded { weight: u32, max_weight: u32 },
/// Unstaking more than the total staked
#[fail(
display = "Tried to unstake more coins than the current stake ({} > {})",
Expand Down
10 changes: 4 additions & 6 deletions data_structures/src/superblock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,13 @@ impl SuperBlockVotesMempool {
}

// Returns true if the identity voted more than once
fn check_double_vote(&self, pkh: &PublicKeyHash, sbv_hash: &Hash) -> bool {
fn check_double_vote(&self, pkh: &PublicKeyHash, sbv: &SuperBlockVote) -> bool {
if self.penalized_identities.contains(pkh) {
true
} else if let Some(vote) = self.votes_of_each_identity.get(pkh) {
// In case of being the same vote, it should not be considered as double vote
sbv_hash != &vote.superblock_hash
sbv.superblock_index == vote.superblock_index
&& sbv.superblock_hash != vote.superblock_hash
} else {
false
}
Expand Down Expand Up @@ -286,10 +287,7 @@ impl SuperBlockState {
// If the superblock vote is valid, store it
let pkh = sbv.secp256k1_signature.public_key.pkh();

if self
.votes_mempool
.check_double_vote(&pkh, &sbv.superblock_hash)
{
if self.votes_mempool.check_double_vote(&pkh, &sbv) {
// This identity has already voted for a different superblock
self.votes_mempool.override_vote(pkh);

Expand Down
8 changes: 8 additions & 0 deletions data_structures/src/transaction_factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -864,6 +864,14 @@ pub fn build_st(
let inputs = used_pointers.collect::<Vec<_>>();
let body = StakeTransactionBody::new(inputs, output, change);

let txn_weight = body.weight();
if txn_weight > max_weight {
return Err(TransactionError::StakeWeightLimitExceeded {
weight: txn_weight,
max_weight,
});
}

Ok(body)
}

Expand Down
13 changes: 7 additions & 6 deletions node/src/actors/json_rpc/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ where
/// Attach the regular JSON-RPC methods to a multi-transport server.
pub fn attach_regular_methods<H>(
server: &mut impl witty_jsonrpc::server::ActixServer<H>,
sensitive_methods_enabled: bool,
system: &Option<actix::System>,
) where
H: witty_jsonrpc::handler::Handler,
Expand All @@ -108,8 +109,8 @@ pub fn attach_regular_methods<H>(
server.add_actix_method(system, "dataRequestReport", |params: Params| {
Box::pin(data_request_report(params.parse()))
});
server.add_actix_method(system, "getBalance", |params: Params| {
Box::pin(get_balance(params))
server.add_actix_method(system, "getBalance", move |params: Params| {
Box::pin(get_balance(params, sensitive_methods_enabled))
});
server.add_actix_method(system, "getBalance2", |params: Params| {
Box::pin(get_balance_2(params.parse()))
Expand Down Expand Up @@ -469,7 +470,7 @@ pub fn attach_api<H>(
) where
H: witty_jsonrpc::handler::Handler,
{
attach_regular_methods(server, system);
attach_regular_methods(server, enable_sensitive_methods, system);
attach_sensitive_methods(server, enable_sensitive_methods, system);
attach_subscriptions(server, subscriptions, system);
}
Expand Down Expand Up @@ -1449,7 +1450,7 @@ impl From<GetBalanceParams> for GetBalanceTarget {
}

/// Get balance
pub async fn get_balance(params: Params) -> JsonRpcResult {
pub async fn get_balance(params: Params, sensitive_methods_enabled: bool) -> JsonRpcResult {
let (target, simple): (GetBalanceTarget, bool);

// Handle parameters as an array with a first obligatory PublicKeyHash field plus an optional bool field
Expand All @@ -1469,9 +1470,9 @@ pub async fn get_balance(params: Params) -> JsonRpcResult {
target = params.into();
};

if target == GetBalanceTarget::Own {
if target == GetBalanceTarget::Own && !sensitive_methods_enabled {
return Err(Error::invalid_params(
"Providing server's balance is not allowed",
"Providing own node's balance is not allowed when sensitive methods are disabled",
));
};

Expand Down
8 changes: 0 additions & 8 deletions src/cli/node/json_rpc_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,14 +211,6 @@ pub fn get_balance(
) -> Result<(), failure::Error> {
let mut stream = start_client(addr)?;

if let GetBalanceTarget::Own = target {
log::info!("No pkh specified, will default to node pkh");
let request = r#"{"jsonrpc": "2.0","method": "getPkh", "id": "1"}"#;
let response = send_request(&mut stream, request)?;
let node_pkh = parse_response::<PublicKeyHash>(&response)?;
log::info!("Node pkh: {}", node_pkh);
}

let request = format!(
r#"{{"jsonrpc": "2.0","method": "getBalance", "params": [{}, {}], "id": "1"}}"#,
serde_json::to_string(&target).unwrap(),
Expand Down
Loading