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

Add Transaction Permissioning Hook to PermissioningService Interface #7952

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

vaidikcode
Copy link
Contributor

Signed-off-by: vaidikcode [email protected]

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?

  • Checked out our contribution guidelines?
  • Considered documentation and added the doc-change-required label to this PR if updates are required.
  • Considered the changelog and included an update if required.
  • For database changes (e.g. KeyValueSegmentIdentifier) considered compatibility and performed forwards and backwards compatibility tests

Locally, you can run these tests to catch failures early:

  • unit tests: ./gradlew build
  • acceptance tests: ./gradlew acceptanceTest
  • integration tests: ./gradlew integrationTest
  • reference tests: ./gradlew ethereum:referenceTests:referenceTests

Signed-off-by: vaidikcode <[email protected]>
@vaidikcode vaidikcode changed the title commit Add Transaction Permissioning Hook to PermissioningService Interface Nov 27, 2024
Copy link
Contributor

@macfarla macfarla left a 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());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
log.info("Transaction {} permitted.", transaction.getHash());
log.debug("Transaction {} permitted.", transaction.getHash());

Copy link
Contributor

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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private static final Logger log = LoggerFactory.getLogger(PermissionServiceImpl.class);
private static final Logger LOG = LoggerFactory.getLogger(PermissionServiceImpl.class);

Copy link
Contributor

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());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
log.info("Transaction {} not permitted by one of the providers.", transaction.getHash());
log.debug("Transaction {} not permitted by one of the providers.", transaction.getHash());

@macfarla macfarla self-assigned this Nov 27, 2024
@macfarla macfarla added the doc-change-required Indicates an issue or PR that requires doc to be updated label Nov 28, 2024
Signed-off-by: vaidikcode <[email protected]>
Signed-off-by: vaidikcode <[email protected]>
Signed-off-by: vaidikcode <[email protected]>
Signed-off-by: vaidikcode <[email protected]>
Signed-off-by: vaidikcode <[email protected]>
Signed-off-by: vaidikcode <[email protected]>
…er#7835

# Conflicts:
#	acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/plugins/PermissioningPluginTest.java
Signed-off-by: vaidikcode <[email protected]>
Copy link
Contributor

@macfarla macfarla left a 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @return if the transaction is valid
* @return whether the transaction is permitted

@@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- 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;
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc-change-required Indicates an issue or PR that requires doc to be updated
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants