-
Notifications
You must be signed in to change notification settings - Fork 295
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
mixing: Add mixpool package. #3082
Merged
Merged
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
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 |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// Copyright (c) 2024 The Decred developers | ||
// Use of this source code is governed by an ISC | ||
// license that can be found in the LICENSE file. | ||
|
||
package mixpool | ||
|
||
import ( | ||
"errors" | ||
|
||
"github.com/decred/dcrd/chaincfg/chainhash" | ||
) | ||
|
||
// RuleError represents a mixpool rule violation. | ||
// | ||
// RuleErrors can be treated as a bannable offense. | ||
type RuleError struct { | ||
Err error | ||
} | ||
|
||
func ruleError(err error) *RuleError { | ||
return &RuleError{Err: err} | ||
} | ||
|
||
func (e *RuleError) Error() string { | ||
return e.Err.Error() | ||
} | ||
|
||
func (e *RuleError) Unwrap() error { | ||
return e.Err | ||
} | ||
|
||
// Errors wrapped by RuleError. | ||
var ( | ||
// ErrChangeDust is returned by AcceptMessage if a pair request's | ||
// change amount is dust. | ||
ErrChangeDust = errors.New("change output is dust") | ||
|
||
// ErrInvalidMessageCount is returned by AcceptMessage if a | ||
// pair request contains an invalid message count. | ||
ErrInvalidMessageCount = errors.New("message count must be positive") | ||
|
||
// ErrInvalidScript is returned by AcceptMessage if a pair request | ||
// contains an invalid script. | ||
ErrInvalidScript = errors.New("invalid script") | ||
|
||
// ErrInvalidSessionID is returned by AcceptMessage if the message | ||
// contains an invalid session id. | ||
ErrInvalidSessionID = errors.New("invalid session ID") | ||
|
||
// ErrInvalidSignature is returned by AcceptMessage if the message is | ||
// not properly signed for the claimed identity. | ||
ErrInvalidSignature = errors.New("invalid message signature") | ||
|
||
// ErrInvalidTotalMixAmount is returned by AcceptMessage if a pair | ||
// request contains the product of the message count and mix amount | ||
// that exceeds the total input value. | ||
ErrInvalidTotalMixAmount = errors.New("invalid total mix amount") | ||
|
||
// ErrInvalidUTXOProof is returned by AcceptMessage if a pair request | ||
// fails to prove ownership of each utxo. | ||
ErrInvalidUTXOProof = errors.New("invalid UTXO ownership proof") | ||
|
||
// ErrMissingUTXOs is returned by AcceptMessage if a pair request | ||
// message does not reference any previous UTXOs. | ||
ErrMissingUTXOs = errors.New("pair request contains no UTXOs") | ||
) | ||
|
||
var ( | ||
// ErrSecretsRevealed is returned by Receive if any peer has | ||
// unexpectedly revealed their secrets during a run stage | ||
// (Received.RSs field is nil). This requires all other peers to quit | ||
// the run, reveal their secrets, and perform blame assignment. | ||
ErrSecretsRevealed = errors.New("secrets revealed by peer") | ||
) | ||
|
||
// MissingOwnPRError represents the error condition where a key exchange | ||
// message cannot be accepted to the mixpool due to it not referencing the | ||
// owner's own pair request. The KE is recorded as an orphan and may be | ||
// processed later. The error contains all unknown PR hashes so they can be | ||
// fetched from another instance. | ||
type MissingOwnPRError struct { | ||
MissingPR chainhash.Hash | ||
} | ||
|
||
func (e *MissingOwnPRError) Error() string { | ||
return "KE identity's own PR is missing from mixpool" | ||
} |
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright (c) 2020-2024 The Decred developers | ||
// Use of this source code is governed by an ISC | ||
// license that can be found in the LICENSE file. | ||
|
||
package mixpool | ||
|
||
import ( | ||
"github.com/decred/slog" | ||
) | ||
|
||
// log is a logger that is initialized with no output filters. This | ||
// means the package will not perform any logging by default until the caller | ||
// requests it. | ||
// The default amount of logging is none. | ||
var log = slog.Disabled | ||
|
||
// UseLogger uses a specified Logger to output package logging info. | ||
// This should be used in preference to SetLogWriter if the caller is also | ||
// using slog. | ||
func UseLogger(logger slog.Logger) { | ||
log = logger | ||
} |
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.
This is also ignoring all of the best practices in the repo for error handling as mentioned in the PR this one depends on.
However, it's fine for the development module, but it's something we'll want to address.
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.
we don't return these bare anyways, they are always wrapped as a RuleError, but are defined as variables so callers can test for the precise reason with errors.Is. This isn't that much unlike the error code method, but reads nicer.