-
Notifications
You must be signed in to change notification settings - Fork 129
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
lib/babe: always use 2/3 of slot to produce block, re-add potentially valid txs to queue #1679
Changes from 13 commits
9c9acde
ba86b2b
d26488d
dc15bc1
4ea0542
829fb09
a232522
a74f872
6226fed
f044113
1f91b03
01e341a
a0cff7a
2c8644a
760c8d9
2258825
4fa0bdb
e08dacc
5dbd0f1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -86,13 +86,33 @@ func (e DispatchOutcomeError) Error() string { | |
|
||
// A TransactionValidityError is possible errors while checking the validity of a transaction | ||
type TransactionValidityError struct { | ||
msg string // description of error | ||
msg transactionValidityErrorMsg // description of error | ||
} | ||
|
||
func (e TransactionValidityError) Error() string { | ||
return fmt.Sprintf("transaction validity error: %s", e.msg) | ||
} | ||
|
||
type transactionValidityErrorMsg string | ||
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. why this type is necessary? 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. so that not any string can be used as the error message, only the predefined ones. I can remove it if you think it's overkill 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. Got it! IMO seems overkill, I think that each of the errors string var could be of the type var (
ErrunexpectedTxCallMsg = errors.New("call of the transaction is not expected")
ErrinvalidPaymentMsg = errors.New("invalid payment")
...
) then, will be easy to determine a if an error occurs: err := determineErrType(...)
if errors.Is(err, ErrunexpectedTxCallMsg) { ... } 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. updated the errors! |
||
|
||
var ( | ||
unexpectedTxCallMsg transactionValidityErrorMsg = "call of the transaction is not expected" | ||
invalidPaymentMsg transactionValidityErrorMsg = "invalid payment" | ||
invalidTransactionMsg transactionValidityErrorMsg = "invalid transaction" | ||
outdatedTransactionMsg transactionValidityErrorMsg = "outdated transaction" | ||
badProofMsg transactionValidityErrorMsg = "bad proof" | ||
ancientBirthBlockMsg transactionValidityErrorMsg = "ancient birth block" | ||
exhaustsResourcesMsg transactionValidityErrorMsg = "exhausts resources" | ||
mandatoryDispatchErrorMsg transactionValidityErrorMsg = "mandatory dispatch error" | ||
invalidMandatoryDispatchMsg transactionValidityErrorMsg = "invalid mandatory dispatch" | ||
lookupFailedMsg transactionValidityErrorMsg = "lookup failed" | ||
validatorNotFoundMsg transactionValidityErrorMsg = "validator not found" | ||
) | ||
|
||
func newUnknownErrorMsg(data scale.VaryingDataTypeValue) transactionValidityErrorMsg { | ||
return transactionValidityErrorMsg(fmt.Sprintf("unknown error: %d", data)) | ||
} | ||
|
||
// UnmarshalError occurs when unmarshalling fails | ||
type UnmarshalError struct { | ||
msg string | ||
|
@@ -223,31 +243,31 @@ func determineErrType(vdt scale.VaryingDataType) error { | |
case Module: | ||
return &DispatchOutcomeError{fmt.Sprintf("custom module error: %s", val.string())} | ||
case Call: | ||
return &TransactionValidityError{"call of the transaction is not expected"} | ||
return &TransactionValidityError{unexpectedTxCallMsg} | ||
case Payment: | ||
return &TransactionValidityError{"invalid payment"} | ||
return &TransactionValidityError{invalidPaymentMsg} | ||
case Future: | ||
return &TransactionValidityError{"invalid transaction"} | ||
return &TransactionValidityError{invalidTransactionMsg} | ||
case Stale: | ||
return &TransactionValidityError{"outdated transaction"} | ||
return &TransactionValidityError{outdatedTransactionMsg} | ||
case BadProof: | ||
return &TransactionValidityError{"bad proof"} | ||
return &TransactionValidityError{badProofMsg} | ||
case AncientBirthBlock: | ||
return &TransactionValidityError{"ancient birth block"} | ||
return &TransactionValidityError{ancientBirthBlockMsg} | ||
case ExhaustsResources: | ||
return &TransactionValidityError{"exhausts resources"} | ||
return &TransactionValidityError{exhaustsResourcesMsg} | ||
case InvalidCustom: | ||
return &TransactionValidityError{fmt.Sprintf("unknown error: %d", val)} | ||
return &TransactionValidityError{newUnknownErrorMsg(val)} | ||
case BadMandatory: | ||
return &TransactionValidityError{"mandatory dispatch error"} | ||
return &TransactionValidityError{mandatoryDispatchErrorMsg} | ||
case MandatoryDispatch: | ||
return &TransactionValidityError{"invalid mandatory dispatch"} | ||
return &TransactionValidityError{invalidMandatoryDispatchMsg} | ||
case ValidityCannotLookup: | ||
return &TransactionValidityError{"lookup failed"} | ||
return &TransactionValidityError{lookupFailedMsg} | ||
case NoUnsignedValidator: | ||
return &TransactionValidityError{"validator not found"} | ||
return &TransactionValidityError{validatorNotFoundMsg} | ||
case UnknownCustom: | ||
return &TransactionValidityError{fmt.Sprintf("unknown error: %d", val)} | ||
return &TransactionValidityError{newUnknownErrorMsg(val)} | ||
} | ||
|
||
return errInvalidResult | ||
|
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.
Use
errors.As(err, &e)
https://blog.golang.org/go1.13-errorsThere 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.
You can remove indentation
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.
done