-
Notifications
You must be signed in to change notification settings - Fork 858
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
Add Transaction Permissioning Hook to PermissioningService Interface #7952
base: main
Are you sure you want to change the base?
Conversation
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.
thanks for the contrib!
a few comments. the logging would be better at info level. you can have extra logging in the plugin if needed, and/or you can use custom log4j config to turn this up for troubleshooting but don't want this permanently at info level. The one-off "registered plugin" is fine at info level.
there's also the TestPermissioningPlugin and PermissioningPluginTest - you could expand the test plugin and add a test to verify the tx permissioning callback works as expected
you'll also need to run the gradle target checkAPIChanges to calculate and update the api hash
and prob add a changelog entry
return false; | ||
} | ||
} | ||
log.info("Transaction {} permitted.", transaction.getHash()); |
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.
log.info("Transaction {} permitted.", transaction.getHash()); | |
log.debug("Transaction {} permitted.", transaction.getHash()); |
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 would be spammy at info level
import java.util.List; | ||
|
||
public class PermissionServiceImpl implements PermissioningService { | ||
private static final Logger log = LoggerFactory.getLogger(PermissionServiceImpl.class); |
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.
private static final Logger log = LoggerFactory.getLogger(PermissionServiceImpl.class); | |
private static final Logger LOG = LoggerFactory.getLogger(PermissionServiceImpl.class); |
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.
all upper case naming convention for static fields
public boolean isTransactionPermitted(Transaction transaction) { | ||
for (TransactionPermissioningProvider provider : transactionPermissioningProviders) { | ||
if (!provider.isPermitted(transaction)) { | ||
log.info("Transaction {} not permitted by one of the providers.", transaction.getHash()); |
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.
log.info("Transaction {} not permitted by one of the providers.", transaction.getHash()); | |
log.debug("Transaction {} not permitted by one of the providers.", transaction.getHash()); |
Signed-off-by: vaidikcode <vaidikbhardwaj00@gmail.com>
Signed-off-by: vaidikcode <vaidikbhardwaj00@gmail.com>
…hen it already exists Signed-off-by: vaidikcode <vaidikbhardwaj00@gmail.com>
Signed-off-by: vaidikcode <vaidikbhardwaj00@gmail.com>
…er#7835 # Conflicts: # acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/plugins/PermissioningPluginTest.java
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.
will need some refactoring to move this TransactionPermissioningProvider interface into the plugin package.
/** | ||
* Gets transaction rules. | ||
* | ||
* @return if the transaction is valid |
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.
* @return if the transaction is valid | |
* @return whether the transaction is permitted |
CHANGELOG.md
Outdated
@@ -32,6 +32,7 @@ | |||
- Fast Sync | |||
|
|||
### Additions and Improvements | |||
- Add support for registeringTransactionPermissionProvider in Plugin API to define and validate transaction rules [#7952](https://github.com/hyperledger/besu/pull/7952) |
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.
- Add support for registeringTransactionPermissionProvider in Plugin API to define and validate transaction rules [#7952](https://github.com/hyperledger/besu/pull/7952) | |
- Add support for transaction permissioning rules in Plugin API [#7952](https://github.com/hyperledger/besu/pull/7952) |
@@ -14,6 +14,7 @@ | |||
*/ | |||
package org.hyperledger.besu.plugin.services; | |||
|
|||
import org.hyperledger.besu.ethereum.permissioning.account.TransactionPermissioningProvider; |
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.
will need some refactoring to move this TransactionPermissioningProvider interface into the plugin package.
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.
Thank you for your feedback! Are you referring to this location: plugin-api/src/main/java/org/hyperledger/besu/plugin/services/permissioning/
?
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 have a quick question: Since the TransactionPermissioningProvider is implemented by both the AccountLocalConfigPermissioningController and the TransactionSmartContractPermissioningController, what would be the best way to move forward with this? Your guidance would be greatly appreciated!
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 would have a look at how NodeMessagePermissioningProvider
(functional interface) is used, since that's already exposed to plugins and used elsewhere in besu. It's a common pattern in besu to have an interface in the plugin-api package which is imported and implemented by classes where needed. BlockHeader
is another good example but you can find lots of examples in the plugin-api package.
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.
There seems to be a circular dependency issue caused by importing the Transaction class into the TransactionPermissioningProvider interface. introducing a lightweight abstraction (like a DTO or a subset of transaction properties) for permissioning logic might be a good solution. wdyt?
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.
does it help if the TransactionPermissioningProvider uses the org.hyperledger.besu.datatypes.Transaction interface instead
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.
Thank you very much. It works perfectly!.
Signed-off-by: Vaidik <vaidikbhardwaj00@gmail.com>
Signed-off-by: Vaidik <vaidikbhardwaj00@gmail.com>
@vaidikcode spotless! |
@vaidikcode still getting compile errors - can you run compile and test tasks locally, your feedback loop will be waaaay faster
|
converting to draft as a signal it's not ready to review |
Signed-off-by: vaidikcode <vaidikbhardwaj00@gmail.com>
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.
couple of comments
also this test is failing when I run locally - PermissioningPluginTest.testGasLimitLogic
@@ -57,6 +57,7 @@ | |||
- Fast Sync | |||
|
|||
### Additions and Improvements | |||
- Add support for transaction permissioning rules in Plugin API [#7952](https://github.com/hyperledger/besu/pull/7952) |
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.
needs to move to "Unreleased" section
encodeAddress(transaction.getTo()), | ||
transaction.getValue(), | ||
transaction.getGasPrice().map(BaseUInt256Value::toBytes).orElse(Bytes32.ZERO), | ||
encodeAddress(transaction.getTo().map(Address.class::cast)), |
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 don't love this line - surely there is a cleaner way todo this
@@ -231,4 +237,16 @@ private static Bytes encodeBytes(final Bytes value) { | |||
final Bytes padding = Bytes.wrap(new byte[(32 - (value.size() % 32))]); | |||
return Bytes.concatenate(dynamicParameterOffset, length, value, padding); | |||
} | |||
|
|||
// Convert the Quantity value to Bytes | |||
private static Bytes convertQuantityToBytes(final Quantity quantity) { |
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.
private static Bytes convertQuantityToBytes(final Quantity quantity) { | |
private static Bytes encodeQuantity(final Quantity quantity) { |
@vaidikcode couple of comments - it's getting there - but tests are still failing. Can you please run tests locally before saying it's ready to review? Your feedback loop will be like 100x faster |
Signed-off-by: vaidikcode vaidikbhardwaj00@gmail.com
PR description
I’ve implemented the registerTransactionPermissioningProvider method to allow custom transaction permissioning logic by adding providers to a collection. A method to iterate over these providers and check if transactions are permitted has also been included.
Currently, other methods in the PermissioningService interface (like registerNodePermissioningProvider and registerNodeMessagePermissioningProvider) are left unimplemented, as they are not part of this PR's scope.
I may need guidance on whether you would like me to proceed with implementing the other methods, and any improvements or adjustments needed to integrate this into the broader permissioning system.
Fixed Issue(s)
#7835
Thanks for sending a pull request! Have you done the following?
doc-change-required
label to this PR if updates are required.Locally, you can run these tests to catch failures early:
./gradlew build
./gradlew acceptanceTest
./gradlew integrationTest
./gradlew ethereum:referenceTests:referenceTests