-
Notifications
You must be signed in to change notification settings - Fork 871
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?
Changes from 10 commits
1724426
858c8ee
dd498e7
aae1526
2509d7d
6c7b463
4a0c5dd
2d51ec2
7851707
da2c3de
dd44cca
549db1f
7f75593
d77f294
245e8ef
b51669b
94620ed
531ff5d
ae8f3c8
5d815c2
9cfc510
80c832c
b74a3e1
0b23b89
de4ee35
040857a
a037c07
028c103
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 | ||||
---|---|---|---|---|---|---|
|
@@ -14,20 +14,27 @@ | |||||
*/ | ||||||
package org.hyperledger.besu.services; | ||||||
|
||||||
import org.hyperledger.besu.ethereum.core.Transaction; | ||||||
import org.hyperledger.besu.ethereum.permissioning.account.TransactionPermissioningProvider; | ||||||
import org.hyperledger.besu.plugin.services.PermissioningService; | ||||||
import org.hyperledger.besu.plugin.services.permissioning.NodeConnectionPermissioningProvider; | ||||||
import org.hyperledger.besu.plugin.services.permissioning.NodeMessagePermissioningProvider; | ||||||
|
||||||
import java.util.ArrayList; | ||||||
import java.util.List; | ||||||
import javax.inject.Inject; | ||||||
|
||||||
import com.google.common.collect.Lists; | ||||||
import org.slf4j.Logger; | ||||||
import org.slf4j.LoggerFactory; | ||||||
|
||||||
/** The Permissioning service implementation. */ | ||||||
public class PermissioningServiceImpl implements PermissioningService { | ||||||
private static final Logger LOG = LoggerFactory.getLogger(PermissioningServiceImpl.class); | ||||||
|
||||||
private final List<NodeConnectionPermissioningProvider> connectionPermissioningProviders = | ||||||
Lists.newArrayList(); | ||||||
private final List<TransactionPermissioningProvider> transactionPermissioningProviders = new ArrayList<>(); | ||||||
|
||||||
/** Default Constructor. */ | ||||||
@Inject | ||||||
|
@@ -39,6 +46,12 @@ public void registerNodePermissioningProvider( | |||||
connectionPermissioningProviders.add(provider); | ||||||
} | ||||||
|
||||||
@Override | ||||||
public void registerTransactionPermissioningProvider(TransactionPermissioningProvider provider) { | ||||||
transactionPermissioningProviders.add(provider); | ||||||
LOG.info("Registered new transaction permissioning provider."); | ||||||
} | ||||||
|
||||||
/** | ||||||
* Gets connection permissioning providers. | ||||||
* | ||||||
|
@@ -65,4 +78,20 @@ public void registerNodeMessagePermissioningProvider( | |||||
public List<NodeMessagePermissioningProvider> getMessagePermissioningProviders() { | ||||||
return messagePermissioningProviders; | ||||||
} | ||||||
|
||||||
/** | ||||||
* Gets transaction rules. | ||||||
* | ||||||
* @return if the transaction is valid | ||||||
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.
Suggested change
|
||||||
*/ | ||||||
public boolean isTransactionPermitted(Transaction transaction) { | ||||||
for (TransactionPermissioningProvider provider : transactionPermissioningProviders) { | ||||||
if (!provider.isPermitted(transaction)) { | ||||||
LOG.debug("Transaction {} not permitted by one of the providers.", transaction.getHash()); | ||||||
return false; | ||||||
} | ||||||
} | ||||||
LOG.debug("Transaction {} permitted.", transaction.getHash()); | ||||||
return true; | ||||||
} | ||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for your feedback! Are you referring to this location: 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. 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 commentThe reason will be displayed to describe this comment to others. Learn more. I would have a look at how 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. 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Thank you very much. It works perfectly!. |
||
import org.hyperledger.besu.plugin.services.permissioning.NodeConnectionPermissioningProvider; | ||
import org.hyperledger.besu.plugin.services.permissioning.NodeMessagePermissioningProvider; | ||
|
||
|
@@ -38,6 +39,13 @@ public interface PermissioningService extends BesuService { | |
*/ | ||
void registerNodePermissioningProvider(NodeConnectionPermissioningProvider provider); | ||
|
||
/** | ||
* Registers a callback for transaction permission. | ||
* | ||
* @param provider The provider to register | ||
*/ | ||
void registerTransactionPermissioningProvider(TransactionPermissioningProvider provider); | ||
|
||
/** | ||
* Registers a callback to allow the interception of a devp2p message sending request | ||
* | ||
|
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.