-
Notifications
You must be signed in to change notification settings - Fork 251
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
Report proposal errors earlier and more precisely where possible #1441
Open
daira
wants to merge
1
commit into
zcash:main
Choose a base branch
from
daira:refactor-errors
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,6 @@ | |
use crate::address::UnifiedAddress; | ||
use crate::data_api::wallet::input_selection::InputSelectorError; | ||
use crate::proposal::ProposalError; | ||
use crate::PoolType; | ||
|
||
#[cfg(feature = "transparent-inputs")] | ||
use zcash_primitives::legacy::TransparentAddress; | ||
|
@@ -33,14 +32,17 @@ | |
/// An error in note selection | ||
NoteSelection(SelectionError), | ||
|
||
/// An error in transaction proposal construction | ||
/// An error in transaction proposal construction. This indicates that the proposal | ||
/// violated balance or structural constraints. | ||
Proposal(ProposalError), | ||
|
||
/// The proposal was structurally valid, but tried to do one of these unsupported things: | ||
/// * spend a prior shielded output; | ||
/// * pay to an output pool for which the corresponding feature is not enabled; | ||
/// * pay to a TEX address if the "transparent-inputs" feature is not enabled. | ||
ProposalNotSupported, | ||
/// A proposal was structurally valid, but not supported by the current feature or | ||
/// chain configuration. | ||
/// | ||
/// This is indicative of a programming error; a transaction proposal that presumes | ||
/// support for the specified pool was decoded or executed using an application that | ||
/// does not provide such support. | ||
ProposalNotSupported(ProposalError), | ||
|
||
/// No account could be found corresponding to a provided spending key. | ||
KeyNotRecognized, | ||
|
@@ -64,13 +66,6 @@ | |
/// It is forbidden to provide a memo when constructing a transparent output. | ||
MemoForbidden, | ||
|
||
/// Attempted to send change to an unsupported pool. | ||
/// | ||
/// This is indicative of a programming error; execution of a transaction proposal that | ||
/// presumes support for the specified pool was performed using an application that does not | ||
/// provide such support. | ||
UnsupportedChangeType(PoolType), | ||
|
||
/// Attempted to create a spend to an unsupported Unified Address receiver | ||
NoSupportedReceivers(Box<UnifiedAddress>), | ||
|
||
|
@@ -123,12 +118,10 @@ | |
Error::Proposal(e) => { | ||
write!(f, "Input selection attempted to construct an invalid proposal: {}", e) | ||
} | ||
Error::ProposalNotSupported => write!( | ||
f, | ||
"The proposal was valid but tried to do something that is not supported \ | ||
(spend shielded outputs of prior transaction steps or use a feature that \ | ||
is not enabled).", | ||
), | ||
Error::ProposalNotSupported(e) => { | ||
// The `ProposalError` message is complete in this context too. | ||
write!(f, "{}", e) | ||
} | ||
Error::KeyNotRecognized => { | ||
write!( | ||
f, | ||
|
@@ -149,7 +142,6 @@ | |
Error::ScanRequired => write!(f, "Must scan blocks first"), | ||
Error::Builder(e) => write!(f, "An error occurred building the transaction: {}", e), | ||
Error::MemoForbidden => write!(f, "It is not possible to send a memo to a transparent address."), | ||
Error::UnsupportedChangeType(t) => write!(f, "Attempted to send change to an unsupported pool type: {}", t), | ||
Error::NoSupportedReceivers(ua) => write!( | ||
f, | ||
"A recipient's unified address does not contain any receivers to which the wallet can send funds; required one of {}", | ||
|
@@ -186,6 +178,7 @@ | |
Error::CommitmentTree(e) => Some(e), | ||
Error::NoteSelection(e) => Some(e), | ||
Error::Proposal(e) => Some(e), | ||
Error::ProposalNotSupported(e) => Some(e), | ||
Error::Builder(e) => Some(e), | ||
_ => None, | ||
} | ||
|
@@ -200,7 +193,14 @@ | |
|
||
impl<DE, CE, SE, FE> From<ProposalError> for Error<DE, CE, SE, FE> { | ||
fn from(e: ProposalError) -> Self { | ||
Error::Proposal(e) | ||
match e { | ||
// These errors concern feature support or unimplemented functionality. | ||
ProposalError::SpendsPaymentFromUnsupportedPool(_) | ||
| ProposalError::PaysUnsupportedPoolRecipient(_) => Error::ProposalNotSupported(e), | ||
Comment on lines
+198
to
+199
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should these variants really be a part of |
||
|
||
// These errors concern balance or structural validity. | ||
_ => Error::Proposal(e), | ||
} | ||
} | ||
} | ||
|
||
|
@@ -221,7 +221,8 @@ | |
match e { | ||
InputSelectorError::DataSource(e) => Error::DataSource(e), | ||
InputSelectorError::Selection(e) => Error::NoteSelection(e), | ||
InputSelectorError::Proposal(e) => Error::Proposal(e), | ||
// Choose `Error::Proposal` or `Error::ProposalNotSupported` as applicable. | ||
InputSelectorError::Proposal(e) => e.into(), | ||
InputSelectorError::InsufficientFunds { | ||
available, | ||
required, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure that having two different variants that wrap
ProposalError
is a good idea; it suggests that the entire state space ofProposalError
is reachable by multiple paths, but the comment here suggests something different, and that only a subset ofProposalError
is reachable via the path that producesProposalNotSupported.