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

Various client improvements 2 #2748

Merged
merged 6 commits into from
Mar 7, 2024
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Various client improvements.
([\#2748](https://github.com/anoma/namada/pull/2748))
5 changes: 4 additions & 1 deletion crates/sdk/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ pub enum TxSubmitError {
/// The address is not a valid steward
#[error("The address {0} is not a valid steward.")]
InvalidSteward(Address),
/// Invalid bond pair
#[error("Invalid bond pair: source {0} cannot bond to validator {1}.")]
InvalidBondPair(Address, Address),
/// Rate of epoch change too large for current epoch
#[error(
"New rate, {0}, is too large of a change with respect to the \
Expand Down Expand Up @@ -265,7 +268,7 @@ pub enum TxSubmitError {
ImplicitInternalError,
/// Unexpected Error
#[error("Unexpected behavior reading the unbonds data has occurred")]
UnboundError,
UnbondError,
/// Epoch not in storage
#[error("Proposal end epoch is not in the storage.")]
EpochNotInStorage,
Expand Down
6 changes: 3 additions & 3 deletions crates/sdk/src/queries/vp/pos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -526,12 +526,12 @@
for result in handle.iter(ctx.state)? {
let (
lazy_map::NestedSubKey::Data {
key: end,
nested_sub_key: lazy_map::SubKey::Data(_start),
key: _start,
nested_sub_key: lazy_map::SubKey::Data(withdrawable),

Check warning on line 530 in crates/sdk/src/queries/vp/pos.rs

View check run for this annotation

Codecov / codecov/patch

crates/sdk/src/queries/vp/pos.rs#L529-L530

Added lines #L529 - L530 were not covered by tests
},
amount,
) = result?;
if end <= epoch {
if epoch >= withdrawable {

Check warning on line 534 in crates/sdk/src/queries/vp/pos.rs

View check run for this annotation

Codecov / codecov/patch

crates/sdk/src/queries/vp/pos.rs#L534

Added line #L534 was not covered by tests
total += amount;
}
}
Expand Down
91 changes: 59 additions & 32 deletions crates/sdk/src/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -848,28 +848,32 @@
)
.await?;

if !rpc::is_steward(context.client(), steward).await && !tx_args.force {
if !rpc::is_steward(context.client(), steward).await {

Check warning on line 851 in crates/sdk/src/tx.rs

View check run for this annotation

Codecov / codecov/patch

crates/sdk/src/tx.rs#L851

Added line #L851 was not covered by tests
edisplay_line!(
context.io(),
"The given address {} is not a steward.",
&steward
);
return Err(Error::from(TxSubmitError::InvalidSteward(
steward.clone(),
)));
if !tx_args.force {
return Err(Error::from(TxSubmitError::InvalidSteward(
steward.clone(),
)));
}

Check warning on line 861 in crates/sdk/src/tx.rs

View check run for this annotation

Codecov / codecov/patch

crates/sdk/src/tx.rs#L857-L861

Added lines #L857 - L861 were not covered by tests
};

let commission = Commission::try_from(commission.as_ref())
.map_err(|e| TxSubmitError::InvalidStewardCommission(e.to_string()))?;

if !commission.is_valid() && !tx_args.force {
if !commission.is_valid() {

Check warning on line 867 in crates/sdk/src/tx.rs

View check run for this annotation

Codecov / codecov/patch

crates/sdk/src/tx.rs#L867

Added line #L867 was not covered by tests
edisplay_line!(
context.io(),
"The sum of all percentage must not be greater than 1."
);
return Err(Error::from(TxSubmitError::InvalidStewardCommission(
"Commission sum is greater than 1.".to_string(),
)));
if !tx_args.force {
return Err(Error::from(TxSubmitError::InvalidStewardCommission(
"Commission sum is greater than 1.".to_string(),
)));
}

Check warning on line 876 in crates/sdk/src/tx.rs

View check run for this annotation

Codecov / codecov/patch

crates/sdk/src/tx.rs#L872-L876

Added lines #L872 - L876 were not covered by tests
}

let data = UpdateStewardCommission {
Expand Down Expand Up @@ -915,15 +919,17 @@
)
.await?;

if !rpc::is_steward(context.client(), steward).await && !tx_args.force {
if !rpc::is_steward(context.client(), steward).await {

Check warning on line 922 in crates/sdk/src/tx.rs

View check run for this annotation

Codecov / codecov/patch

crates/sdk/src/tx.rs#L922

Added line #L922 was not covered by tests
edisplay_line!(
context.io(),
"The given address {} is not a steward.",
&steward
);
return Err(Error::from(TxSubmitError::InvalidSteward(
steward.clone(),
)));
if !tx_args.force {
return Err(Error::from(TxSubmitError::InvalidSteward(
steward.clone(),
)));
}

Check warning on line 932 in crates/sdk/src/tx.rs

View check run for this annotation

Codecov / codecov/patch

crates/sdk/src/tx.rs#L928-L932

Added lines #L928 - L932 were not covered by tests
};

build(
Expand Down Expand Up @@ -1307,21 +1313,21 @@
Some(pipeline_epoch),
)
.await?;
if dest_validator_state_at_pipeline == Some(ValidatorState::Inactive)
&& !tx_args.force
{
if dest_validator_state_at_pipeline == Some(ValidatorState::Inactive) {

Check warning on line 1316 in crates/sdk/src/tx.rs

View check run for this annotation

Codecov / codecov/patch

crates/sdk/src/tx.rs#L1316

Added line #L1316 was not covered by tests
edisplay_line!(
context.io(),
"WARNING: the given destination validator address {} is inactive \
at the pipeline epoch {}. If you would still like to bond to the \
inactive validator, use the --force option.",
at the pipeline epoch {}. If you would still like to redelegate \
to the inactive validator, use the --force option.",

Check warning on line 1321 in crates/sdk/src/tx.rs

View check run for this annotation

Codecov / codecov/patch

crates/sdk/src/tx.rs#L1320-L1321

Added lines #L1320 - L1321 were not covered by tests
&dest_validator,
&pipeline_epoch
);
return Err(Error::from(TxSubmitError::ValidatorInactive(
dest_validator.clone(),
pipeline_epoch,
)));
if !tx_args.force {
return Err(Error::from(TxSubmitError::ValidatorInactive(
dest_validator.clone(),
pipeline_epoch,
)));
}

Check warning on line 1330 in crates/sdk/src/tx.rs

View check run for this annotation

Codecov / codecov/patch

crates/sdk/src/tx.rs#L1325-L1330

Added lines #L1325 - L1330 were not covered by tests
}

// There must be at least as many tokens in the bond as the requested
Expand Down Expand Up @@ -1712,7 +1718,7 @@
occurred"
);
} else {
return Err(Error::from(TxSubmitError::UnboundError));
return Err(Error::from(TxSubmitError::UnbondError));

Check warning on line 1721 in crates/sdk/src/tx.rs

View check run for this annotation

Codecov / codecov/patch

crates/sdk/src/tx.rs#L1721

Added line #L1721 was not covered by tests
}
}
std::cmp::Ordering::Equal => {
Expand Down Expand Up @@ -1773,13 +1779,34 @@
.await?;

// Check that the source address exists on chain
let mut is_src_also_val = false;

Check warning on line 1782 in crates/sdk/src/tx.rs

View check run for this annotation

Codecov / codecov/patch

crates/sdk/src/tx.rs#L1782

Added line #L1782 was not covered by tests
let source = match source.clone() {
Some(source) => source_exists_or_err(source, tx_args.force, context)
.await
.map(Some),
Some(source) => {
is_src_also_val =
rpc::is_validator(context.client(), &source).await?;
source_exists_or_err(source, tx_args.force, context)
.await
.map(Some)

Check warning on line 1789 in crates/sdk/src/tx.rs

View check run for this annotation

Codecov / codecov/patch

crates/sdk/src/tx.rs#L1784-L1789

Added lines #L1784 - L1789 were not covered by tests
}
None => Ok(source.clone()),
}?;

// Check that the source is not a different validator bonding to validator
if is_src_also_val && source != Some(validator.clone()) {
edisplay_line!(
context.io(),
"The given source address {} is a validator. A validator is \
prohibited from bonding to another validator.",
&source.clone().unwrap()
);
if !tx_args.force {
return Err(Error::from(TxSubmitError::InvalidBondPair(
source.clone().unwrap(),
validator.clone(),
)));
}
}

Check warning on line 1808 in crates/sdk/src/tx.rs

View check run for this annotation

Codecov / codecov/patch

crates/sdk/src/tx.rs#L1795-L1808

Added lines #L1795 - L1808 were not covered by tests

// Give a bonding warning based on the pipeline state
let params: PosParams = rpc::get_pos_params(context.client()).await?;
let current_epoch = rpc::query_epoch(context.client()).await?;
Expand All @@ -1790,9 +1817,7 @@
Some(pipeline_epoch),
)
.await?;
if validator_state_at_pipeline == Some(ValidatorState::Inactive)
&& !tx_args.force
{
if validator_state_at_pipeline == Some(ValidatorState::Inactive) {

Check warning on line 1820 in crates/sdk/src/tx.rs

View check run for this annotation

Codecov / codecov/patch

crates/sdk/src/tx.rs#L1820

Added line #L1820 was not covered by tests
edisplay_line!(
context.io(),
"WARNING: the given validator address {} is inactive at the \
Expand All @@ -1801,10 +1826,12 @@
&validator,
&pipeline_epoch
);
return Err(Error::from(TxSubmitError::ValidatorInactive(
validator.clone(),
pipeline_epoch,
)));
if !tx_args.force {
return Err(Error::from(TxSubmitError::ValidatorInactive(
validator.clone(),
pipeline_epoch,
)));
}

Check warning on line 1834 in crates/sdk/src/tx.rs

View check run for this annotation

Codecov / codecov/patch

crates/sdk/src/tx.rs#L1829-L1834

Added lines #L1829 - L1834 were not covered by tests
}

let default_address = source.clone().unwrap_or(validator.clone());
Expand Down
Loading