From 172442609a0e6b1b5fea07f30388134b092a12fe Mon Sep 17 00:00:00 2001 From: vaidikcode Date: Thu, 28 Nov 2024 02:16:44 +0530 Subject: [PATCH 01/18] commit Signed-off-by: vaidikcode --- .../besu/services/PermissionServiceImpl.java | 45 +++++++++++++++++++ .../plugin/services/PermissioningService.java | 8 ++++ 2 files changed, 53 insertions(+) create mode 100644 besu/src/main/java/org/hyperledger/besu/services/PermissionServiceImpl.java diff --git a/besu/src/main/java/org/hyperledger/besu/services/PermissionServiceImpl.java b/besu/src/main/java/org/hyperledger/besu/services/PermissionServiceImpl.java new file mode 100644 index 00000000000..56bbb24e2ee --- /dev/null +++ b/besu/src/main/java/org/hyperledger/besu/services/PermissionServiceImpl.java @@ -0,0 +1,45 @@ +package org.hyperledger.besu.services; + +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 org.hyperledger.besu.ethereum.core.Transaction; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; +import java.util.List; + +public class PermissionServiceImpl implements PermissioningService { + private static final Logger log = LoggerFactory.getLogger(PermissionServiceImpl.class); + private final List transactionPermissioningProviders = new ArrayList<>(); + + @Override + public void registerNodePermissioningProvider(NodeConnectionPermissioningProvider provider) { + + } + + @Override + public void registerTransactionPermissioningProvider(TransactionPermissioningProvider provider) { + transactionPermissioningProviders.add(provider); + log.info("Registered new transaction permissioning provider."); + } + + @Override + public void registerNodeMessagePermissioningProvider(NodeMessagePermissioningProvider provider) { + + } + + 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()); + return false; + } + } + log.info("Transaction {} permitted.", transaction.getHash()); + return true; + } +} + diff --git a/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/PermissioningService.java b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/PermissioningService.java index a9fd6785050..f705b8d18ee 100644 --- a/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/PermissioningService.java +++ b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/PermissioningService.java @@ -14,6 +14,7 @@ */ package org.hyperledger.besu.plugin.services; +import org.hyperledger.besu.ethereum.permissioning.account.TransactionPermissioningProvider; 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 * From 858c8eeb6c8384468d736aab88db85cf63250239 Mon Sep 17 00:00:00 2001 From: vaidikcode Date: Thu, 28 Nov 2024 10:47:16 +0530 Subject: [PATCH 02/18] addressing comments Signed-off-by: vaidikcode --- .../hyperledger/besu/services/PermissionServiceImpl.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/besu/src/main/java/org/hyperledger/besu/services/PermissionServiceImpl.java b/besu/src/main/java/org/hyperledger/besu/services/PermissionServiceImpl.java index 56bbb24e2ee..5b03c616099 100644 --- a/besu/src/main/java/org/hyperledger/besu/services/PermissionServiceImpl.java +++ b/besu/src/main/java/org/hyperledger/besu/services/PermissionServiceImpl.java @@ -12,7 +12,7 @@ import java.util.List; public class PermissionServiceImpl implements PermissioningService { - private static final Logger log = LoggerFactory.getLogger(PermissionServiceImpl.class); + private static final Logger LOG = LoggerFactory.getLogger(PermissionServiceImpl.class); private final List transactionPermissioningProviders = new ArrayList<>(); @Override @@ -23,7 +23,7 @@ public void registerNodePermissioningProvider(NodeConnectionPermissioningProvide @Override public void registerTransactionPermissioningProvider(TransactionPermissioningProvider provider) { transactionPermissioningProviders.add(provider); - log.info("Registered new transaction permissioning provider."); + LOG.info("Registered new transaction permissioning provider."); } @Override @@ -34,11 +34,11 @@ public void registerNodeMessagePermissioningProvider(NodeMessagePermissioningPro 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()); + LOG.debug("Transaction {} not permitted by one of the providers.", transaction.getHash()); return false; } } - log.info("Transaction {} permitted.", transaction.getHash()); + LOG.debug("Transaction {} permitted.", transaction.getHash()); return true; } } From dd498e7d897fa1b9048465b1315509c365478f46 Mon Sep 17 00:00:00 2001 From: vaidikcode Date: Thu, 28 Nov 2024 11:29:43 +0530 Subject: [PATCH 03/18] updating api hash Signed-off-by: vaidikcode --- plugin-api/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin-api/build.gradle b/plugin-api/build.gradle index 067fe5bd7e0..ea6ce410dc2 100644 --- a/plugin-api/build.gradle +++ b/plugin-api/build.gradle @@ -71,7 +71,7 @@ Calculated : ${currentHash} tasks.register('checkAPIChanges', FileStateChecker) { description = "Checks that the API for the Plugin-API project does not change without deliberate thought" files = sourceSets.main.allJava.files - knownHash = 'f6fi+lsYVZtFjmGOyiMPPCfNDie4SIPpj6HVgXRxF8Q=' + knownHash = '3LJPysmUYg0xxYVX7SkUs0qD9WUzOm45/+8RnB2DpHI=' } check.dependsOn('checkAPIChanges') From aae1526ee4928a1784e6fc8fff607c90940c12e6 Mon Sep 17 00:00:00 2001 From: vaidikcode Date: Thu, 28 Nov 2024 12:06:03 +0530 Subject: [PATCH 04/18] fixing the issue of implementing the permission service class in pr when it already exists Signed-off-by: vaidikcode --- .../besu/services/PermissionServiceImpl.java | 45 ------------------- .../services/PermissioningServiceImpl.java | 29 ++++++++++++ 2 files changed, 29 insertions(+), 45 deletions(-) delete mode 100644 besu/src/main/java/org/hyperledger/besu/services/PermissionServiceImpl.java diff --git a/besu/src/main/java/org/hyperledger/besu/services/PermissionServiceImpl.java b/besu/src/main/java/org/hyperledger/besu/services/PermissionServiceImpl.java deleted file mode 100644 index 5b03c616099..00000000000 --- a/besu/src/main/java/org/hyperledger/besu/services/PermissionServiceImpl.java +++ /dev/null @@ -1,45 +0,0 @@ -package org.hyperledger.besu.services; - -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 org.hyperledger.besu.ethereum.core.Transaction; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.ArrayList; -import java.util.List; - -public class PermissionServiceImpl implements PermissioningService { - private static final Logger LOG = LoggerFactory.getLogger(PermissionServiceImpl.class); - private final List transactionPermissioningProviders = new ArrayList<>(); - - @Override - public void registerNodePermissioningProvider(NodeConnectionPermissioningProvider provider) { - - } - - @Override - public void registerTransactionPermissioningProvider(TransactionPermissioningProvider provider) { - transactionPermissioningProviders.add(provider); - LOG.info("Registered new transaction permissioning provider."); - } - - @Override - public void registerNodeMessagePermissioningProvider(NodeMessagePermissioningProvider provider) { - - } - - 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; - } -} - diff --git a/besu/src/main/java/org/hyperledger/besu/services/PermissioningServiceImpl.java b/besu/src/main/java/org/hyperledger/besu/services/PermissioningServiceImpl.java index e43bf1c054e..9fbd677fb60 100644 --- a/besu/src/main/java/org/hyperledger/besu/services/PermissioningServiceImpl.java +++ b/besu/src/main/java/org/hyperledger/besu/services/PermissioningServiceImpl.java @@ -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 connectionPermissioningProviders = Lists.newArrayList(); + private final List 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 getMessagePermissioningProviders() { return messagePermissioningProviders; } + + /** + * Gets transaction rules. + * + * @return if the transaction is valid + */ + 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; + } } From 2509d7d0be6ebbf5313378aadb3b7673ba5073ee Mon Sep 17 00:00:00 2001 From: vaidikcode Date: Thu, 28 Nov 2024 23:34:19 +0530 Subject: [PATCH 05/18] add tests Signed-off-by: vaidikcode --- .../plugins/TestPermissioningPlugin.java | 20 +++++++++++++++++++ .../plugins/PermissioningPluginTest.java | 20 +++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/TestPermissioningPlugin.java b/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/TestPermissioningPlugin.java index b41bcbc4a5f..436dfedf051 100644 --- a/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/TestPermissioningPlugin.java +++ b/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/TestPermissioningPlugin.java @@ -19,6 +19,7 @@ import org.hyperledger.besu.plugin.services.PermissioningService; import org.hyperledger.besu.plugin.services.PicoCLIOptions; + import com.google.auto.service.AutoService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -76,6 +77,25 @@ public void beforeExternalServices() { } return true; }); + + service.registerTransactionPermissioningProvider( + (provider) -> { + long configuredGasLimitThreshold = 12000L; + + long gasLimit = provider.getGasLimit(); + + LOG.info("Transaction gas limit: {} | Configured threshold: {}", gasLimit, configuredGasLimitThreshold); + + if (gasLimit > configuredGasLimitThreshold) { + LOG.debug("Transaction gas limit {} exceeds threshold. Allowing transaction.", gasLimit); + return true; + } + + LOG.debug("Transaction gas limit {} below threshold. Rejecting transaction.", gasLimit); + return false; + } + ); + } } diff --git a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/plugins/PermissioningPluginTest.java b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/plugins/PermissioningPluginTest.java index c469802fc1e..03fbb64743f 100644 --- a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/plugins/PermissioningPluginTest.java +++ b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/plugins/PermissioningPluginTest.java @@ -27,6 +27,8 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; + public class PermissioningPluginTest extends AcceptanceTestBase { private BesuNode minerNode; @@ -34,6 +36,8 @@ public class PermissioningPluginTest extends AcceptanceTestBase { private BesuNode bobNode; private BesuNode charlieNode; + private static final long GAS_LIMIT_THRESHOLD = 12000L; + @BeforeEach public void setUp() throws Exception { minerNode = besu.create(createNodeBuilder().name("miner").build()); @@ -96,4 +100,20 @@ public void transactionsAreNotSendToBlockPendingTransactionsNode() { charlieNode.verify(txPoolConditions.notInTransactionPool(txHash)); minerNode.verify(txPoolConditions.inTransactionPool(txHash)); } + + @Test + public void testGasLimitLogic() { + final long transactionGasLimit = 10000L; + boolean isTransactionPermitted = checkTransactionGasLimit(transactionGasLimit); + + assertThat(isTransactionPermitted).isTrue(); + } + + private boolean checkTransactionGasLimit(long gasLimit) { + if (gasLimit > GAS_LIMIT_THRESHOLD) { + return true; + } else { + return false; + } + } } From 6c7b46337940c91662b3d78490d61a82c6befd56 Mon Sep 17 00:00:00 2001 From: vaidikcode Date: Fri, 29 Nov 2024 00:12:45 +0530 Subject: [PATCH 06/18] change log Signed-off-by: vaidikcode --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 45ba4a00508..4904dd85865 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) - Fine tune already seen txs tracker when a tx is removed from the pool [#7755](https://github.com/hyperledger/besu/pull/7755) - Support for enabling and configuring TLS/mTLS in WebSocket service. [#7854](https://github.com/hyperledger/besu/pull/7854) - Create and publish Besu BOM (Bill of Materials) [#7615](https://github.com/hyperledger/besu/pull/7615) From 4a0c5dd4bd7a92365dac026fd0f5b43d468e0fa5 Mon Sep 17 00:00:00 2001 From: vaidikcode Date: Fri, 29 Nov 2024 00:47:11 +0530 Subject: [PATCH 07/18] fix Signed-off-by: vaidikcode --- .../plugins/PermissioningPluginTest.java | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/plugins/PermissioningPluginTest.java b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/plugins/PermissioningPluginTest.java index 03fbb64743f..0f289ef2c94 100644 --- a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/plugins/PermissioningPluginTest.java +++ b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/plugins/PermissioningPluginTest.java @@ -36,8 +36,6 @@ public class PermissioningPluginTest extends AcceptanceTestBase { private BesuNode bobNode; private BesuNode charlieNode; - private static final long GAS_LIMIT_THRESHOLD = 12000L; - @BeforeEach public void setUp() throws Exception { minerNode = besu.create(createNodeBuilder().name("miner").build()); @@ -100,20 +98,4 @@ public void transactionsAreNotSendToBlockPendingTransactionsNode() { charlieNode.verify(txPoolConditions.notInTransactionPool(txHash)); minerNode.verify(txPoolConditions.inTransactionPool(txHash)); } - - @Test - public void testGasLimitLogic() { - final long transactionGasLimit = 10000L; - boolean isTransactionPermitted = checkTransactionGasLimit(transactionGasLimit); - - assertThat(isTransactionPermitted).isTrue(); - } - - private boolean checkTransactionGasLimit(long gasLimit) { - if (gasLimit > GAS_LIMIT_THRESHOLD) { - return true; - } else { - return false; - } - } } From 2d51ec22696459a8a0c278e1c9eb2f6ad5537e9e Mon Sep 17 00:00:00 2001 From: vaidikcode Date: Fri, 29 Nov 2024 01:40:42 +0530 Subject: [PATCH 08/18] fix Signed-off-by: vaidikcode --- acceptance-tests/test-plugins/build.gradle | 1 + .../plugins/TestPermissioningPlugin.java | 16 ++++---------- .../plugins/PermissioningPluginTest.java | 22 ++++++++++++------- 3 files changed, 19 insertions(+), 20 deletions(-) diff --git a/acceptance-tests/test-plugins/build.gradle b/acceptance-tests/test-plugins/build.gradle index 7c70c52c81f..2fde2783a61 100644 --- a/acceptance-tests/test-plugins/build.gradle +++ b/acceptance-tests/test-plugins/build.gradle @@ -9,6 +9,7 @@ dependencies { implementation project(':ethereum:rlp') implementation project(':ethereum:api') implementation project(':plugin-api') + implementation project(':ethereum:permissioning') implementation 'com.google.auto.service:auto-service' implementation 'info.picocli:picocli' diff --git a/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/TestPermissioningPlugin.java b/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/TestPermissioningPlugin.java index 436dfedf051..adc4bc12812 100644 --- a/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/TestPermissioningPlugin.java +++ b/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/TestPermissioningPlugin.java @@ -79,23 +79,15 @@ public void beforeExternalServices() { }); service.registerTransactionPermissioningProvider( - (provider) -> { + transaction -> { long configuredGasLimitThreshold = 12000L; - - long gasLimit = provider.getGasLimit(); - + long gasLimit = transaction.getGasLimit(); LOG.info("Transaction gas limit: {} | Configured threshold: {}", gasLimit, configuredGasLimitThreshold); - - if (gasLimit > configuredGasLimitThreshold) { - LOG.debug("Transaction gas limit {} exceeds threshold. Allowing transaction.", gasLimit); - return true; - } - - LOG.debug("Transaction gas limit {} below threshold. Rejecting transaction.", gasLimit); - return false; + return gasLimit > configuredGasLimitThreshold; } ); + } } diff --git a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/plugins/PermissioningPluginTest.java b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/plugins/PermissioningPluginTest.java index 03fbb64743f..14ba50ef1ec 100644 --- a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/plugins/PermissioningPluginTest.java +++ b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/plugins/PermissioningPluginTest.java @@ -103,17 +103,23 @@ public void transactionsAreNotSendToBlockPendingTransactionsNode() { @Test public void testGasLimitLogic() { - final long transactionGasLimit = 10000L; - boolean isTransactionPermitted = checkTransactionGasLimit(transactionGasLimit); + long transactionGasLimitAboveThreshold = 13000L; + long transactionGasLimitBelowThreshold = 8000L; - assertThat(isTransactionPermitted).isTrue(); + boolean isAboveThresholdPermitted = checkTransactionGasLimit(transactionGasLimitAboveThreshold); + boolean isBelowThresholdPermitted = checkTransactionGasLimit(transactionGasLimitBelowThreshold); + + assertThat(isAboveThresholdPermitted).isTrue(); + assertThat(isBelowThresholdPermitted).isFalse(); } + /** + * Helper method to check whether a transaction's gas limit is above the defined threshold. + * + * @param gasLimit the gas limit of the transaction + * @return true if the transaction is permitted (gas limit > threshold), false otherwise + */ private boolean checkTransactionGasLimit(long gasLimit) { - if (gasLimit > GAS_LIMIT_THRESHOLD) { - return true; - } else { - return false; - } + return gasLimit > GAS_LIMIT_THRESHOLD; // Logic to check gas limit } } From da2c3de1238a8f0a6441b755539585e8d8f0b23f Mon Sep 17 00:00:00 2001 From: vaidikcode Date: Fri, 29 Nov 2024 01:42:39 +0530 Subject: [PATCH 09/18] fix Signed-off-by: vaidikcode --- .../besu/tests/acceptance/plugins/TestPermissioningPlugin.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/TestPermissioningPlugin.java b/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/TestPermissioningPlugin.java index adc4bc12812..36643b5fa2c 100644 --- a/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/TestPermissioningPlugin.java +++ b/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/TestPermissioningPlugin.java @@ -82,7 +82,7 @@ public void beforeExternalServices() { transaction -> { long configuredGasLimitThreshold = 12000L; long gasLimit = transaction.getGasLimit(); - LOG.info("Transaction gas limit: {} | Configured threshold: {}", gasLimit, configuredGasLimitThreshold); + LOG.info("Transaction gas limit: {} | Configured threshold: {} ", gasLimit, configuredGasLimitThreshold); return gasLimit > configuredGasLimitThreshold; } ); From dd44ccae7d8de5d7fe245d7c1cc38635b06a9067 Mon Sep 17 00:00:00 2001 From: vaidikcode Date: Fri, 29 Nov 2024 04:20:09 +0530 Subject: [PATCH 10/18] fix Signed-off-by: vaidikcode --- CHANGELOG.md | 2 +- .../org/hyperledger/besu/services/PermissioningServiceImpl.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4904dd85865..54213db1a7d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,7 +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) +- Add support for transaction permissioning rules in Plugin API [#7952](https://github.com/hyperledger/besu/pull/7952) - Fine tune already seen txs tracker when a tx is removed from the pool [#7755](https://github.com/hyperledger/besu/pull/7755) - Support for enabling and configuring TLS/mTLS in WebSocket service. [#7854](https://github.com/hyperledger/besu/pull/7854) - Create and publish Besu BOM (Bill of Materials) [#7615](https://github.com/hyperledger/besu/pull/7615) diff --git a/besu/src/main/java/org/hyperledger/besu/services/PermissioningServiceImpl.java b/besu/src/main/java/org/hyperledger/besu/services/PermissioningServiceImpl.java index 9fbd677fb60..343eb243394 100644 --- a/besu/src/main/java/org/hyperledger/besu/services/PermissioningServiceImpl.java +++ b/besu/src/main/java/org/hyperledger/besu/services/PermissioningServiceImpl.java @@ -82,7 +82,7 @@ public List getMessagePermissioningProviders() /** * Gets transaction rules. * - * @return if the transaction is valid + * @return whether the transaction is permitted */ public boolean isTransactionPermitted(Transaction transaction) { for (TransactionPermissioningProvider provider : transactionPermissioningProviders) { From 549db1f604974eedb6f61934958b6c2d6245584c Mon Sep 17 00:00:00 2001 From: vaidikcode Date: Tue, 3 Dec 2024 22:12:36 +0530 Subject: [PATCH 11/18] fix Signed-off-by: vaidikcode --- plugin-api/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin-api/build.gradle b/plugin-api/build.gradle index ea6ce410dc2..078f37eb5a4 100644 --- a/plugin-api/build.gradle +++ b/plugin-api/build.gradle @@ -71,7 +71,7 @@ Calculated : ${currentHash} tasks.register('checkAPIChanges', FileStateChecker) { description = "Checks that the API for the Plugin-API project does not change without deliberate thought" files = sourceSets.main.allJava.files - knownHash = '3LJPysmUYg0xxYVX7SkUs0qD9WUzOm45/+8RnB2DpHI=' + knownHash = 'zuu5jdZ35LcQyu3g2+p+4rcwUhCAY3woS+ZuAxSFCSg=' } check.dependsOn('checkAPIChanges') From d77f29401ac0180c22bd58635e220838178311f7 Mon Sep 17 00:00:00 2001 From: vaidikcode Date: Tue, 3 Dec 2024 22:31:36 +0530 Subject: [PATCH 12/18] refactor Signed-off-by: vaidikcode --- .../services/PermissioningServiceImpl.java | 2 +- ...untLocalConfigPermissioningController.java | 2 +- ...nSmartContractPermissioningController.java | 2 +- .../TransactionPermissioningProvider.java | 22 ------------------- plugin-api/build.gradle | 2 +- .../plugin/services/PermissioningService.java | 2 +- .../TransactionPermissioningProvider.java | 8 +++++++ 7 files changed, 13 insertions(+), 27 deletions(-) delete mode 100644 ethereum/permissioning/src/main/java/org/hyperledger/besu/ethereum/permissioning/account/TransactionPermissioningProvider.java create mode 100644 plugin-api/src/main/java/org/hyperledger/besu/plugin/services/permissioning/TransactionPermissioningProvider.java diff --git a/besu/src/main/java/org/hyperledger/besu/services/PermissioningServiceImpl.java b/besu/src/main/java/org/hyperledger/besu/services/PermissioningServiceImpl.java index 343eb243394..49ac8bb3191 100644 --- a/besu/src/main/java/org/hyperledger/besu/services/PermissioningServiceImpl.java +++ b/besu/src/main/java/org/hyperledger/besu/services/PermissioningServiceImpl.java @@ -15,10 +15,10 @@ 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 org.hyperledger.besu.plugin.services.permissioning.TransactionPermissioningProvider; import java.util.ArrayList; import java.util.List; diff --git a/ethereum/permissioning/src/main/java/org/hyperledger/besu/ethereum/permissioning/AccountLocalConfigPermissioningController.java b/ethereum/permissioning/src/main/java/org/hyperledger/besu/ethereum/permissioning/AccountLocalConfigPermissioningController.java index cb1aa2fd0a1..690f18057ad 100644 --- a/ethereum/permissioning/src/main/java/org/hyperledger/besu/ethereum/permissioning/AccountLocalConfigPermissioningController.java +++ b/ethereum/permissioning/src/main/java/org/hyperledger/besu/ethereum/permissioning/AccountLocalConfigPermissioningController.java @@ -18,7 +18,7 @@ import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.permissioning.AllowlistPersistor.ALLOWLIST_TYPE; -import org.hyperledger.besu.ethereum.permissioning.account.TransactionPermissioningProvider; +import org.hyperledger.besu.plugin.services.permissioning.TransactionPermissioningProvider; import org.hyperledger.besu.metrics.BesuMetricCategory; import org.hyperledger.besu.plugin.services.MetricsSystem; import org.hyperledger.besu.plugin.services.metrics.Counter; diff --git a/ethereum/permissioning/src/main/java/org/hyperledger/besu/ethereum/permissioning/TransactionSmartContractPermissioningController.java b/ethereum/permissioning/src/main/java/org/hyperledger/besu/ethereum/permissioning/TransactionSmartContractPermissioningController.java index dd42727af85..e26cc4367f7 100644 --- a/ethereum/permissioning/src/main/java/org/hyperledger/besu/ethereum/permissioning/TransactionSmartContractPermissioningController.java +++ b/ethereum/permissioning/src/main/java/org/hyperledger/besu/ethereum/permissioning/TransactionSmartContractPermissioningController.java @@ -20,7 +20,7 @@ import org.hyperledger.besu.crypto.Hash; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.ethereum.core.Transaction; -import org.hyperledger.besu.ethereum.permissioning.account.TransactionPermissioningProvider; +import org.hyperledger.besu.plugin.services.permissioning.TransactionPermissioningProvider; import org.hyperledger.besu.ethereum.transaction.CallParameter; import org.hyperledger.besu.ethereum.transaction.TransactionSimulator; import org.hyperledger.besu.ethereum.transaction.TransactionSimulatorResult; diff --git a/ethereum/permissioning/src/main/java/org/hyperledger/besu/ethereum/permissioning/account/TransactionPermissioningProvider.java b/ethereum/permissioning/src/main/java/org/hyperledger/besu/ethereum/permissioning/account/TransactionPermissioningProvider.java deleted file mode 100644 index 9feee8e0079..00000000000 --- a/ethereum/permissioning/src/main/java/org/hyperledger/besu/ethereum/permissioning/account/TransactionPermissioningProvider.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright ConsenSys AG. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ -package org.hyperledger.besu.ethereum.permissioning.account; - -import org.hyperledger.besu.ethereum.core.Transaction; - -@FunctionalInterface -public interface TransactionPermissioningProvider { - boolean isPermitted(final Transaction transaction); -} diff --git a/plugin-api/build.gradle b/plugin-api/build.gradle index 078f37eb5a4..3dd64323219 100644 --- a/plugin-api/build.gradle +++ b/plugin-api/build.gradle @@ -71,7 +71,7 @@ Calculated : ${currentHash} tasks.register('checkAPIChanges', FileStateChecker) { description = "Checks that the API for the Plugin-API project does not change without deliberate thought" files = sourceSets.main.allJava.files - knownHash = 'zuu5jdZ35LcQyu3g2+p+4rcwUhCAY3woS+ZuAxSFCSg=' + knownHash = 'rJfdsomLThb+igDcRPJhifZtLURQlFPqvvL9qtFxXHs=' } check.dependsOn('checkAPIChanges') diff --git a/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/PermissioningService.java b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/PermissioningService.java index f705b8d18ee..8a13dd7c728 100644 --- a/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/PermissioningService.java +++ b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/PermissioningService.java @@ -14,7 +14,7 @@ */ package org.hyperledger.besu.plugin.services; -import org.hyperledger.besu.ethereum.permissioning.account.TransactionPermissioningProvider; +import org.hyperledger.besu.plugin.services.permissioning.TransactionPermissioningProvider; import org.hyperledger.besu.plugin.services.permissioning.NodeConnectionPermissioningProvider; import org.hyperledger.besu.plugin.services.permissioning.NodeMessagePermissioningProvider; diff --git a/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/permissioning/TransactionPermissioningProvider.java b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/permissioning/TransactionPermissioningProvider.java new file mode 100644 index 00000000000..7498615fc8c --- /dev/null +++ b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/permissioning/TransactionPermissioningProvider.java @@ -0,0 +1,8 @@ +package org.hyperledger.besu.plugin.services.permissioning; + +import org.hyperledger.besu.ethereum.core.Transaction; + +@FunctionalInterface +public interface TransactionPermissioningProvider { + boolean isPermitted(final Transaction transaction); +} From 94620edaaebc8445c0eca7df81939d5b2e04ca34 Mon Sep 17 00:00:00 2001 From: vaidikcode Date: Mon, 9 Dec 2024 14:49:40 +0530 Subject: [PATCH 13/18] fix Signed-off-by: vaidikcode --- acceptance-tests/test-plugins/build.gradle | 1 - .../services/PermissioningServiceImpl.java | 2 +- ...untLocalConfigPermissioningController.java | 2 +- ...nSmartContractPermissioningController.java | 27 +++++++++++++++---- plugin-api/build.gradle | 2 +- .../TransactionPermissioningProvider.java | 2 +- 6 files changed, 26 insertions(+), 10 deletions(-) diff --git a/acceptance-tests/test-plugins/build.gradle b/acceptance-tests/test-plugins/build.gradle index 2fde2783a61..7c70c52c81f 100644 --- a/acceptance-tests/test-plugins/build.gradle +++ b/acceptance-tests/test-plugins/build.gradle @@ -9,7 +9,6 @@ dependencies { implementation project(':ethereum:rlp') implementation project(':ethereum:api') implementation project(':plugin-api') - implementation project(':ethereum:permissioning') implementation 'com.google.auto.service:auto-service' implementation 'info.picocli:picocli' diff --git a/besu/src/main/java/org/hyperledger/besu/services/PermissioningServiceImpl.java b/besu/src/main/java/org/hyperledger/besu/services/PermissioningServiceImpl.java index 49ac8bb3191..6c3efa30c1c 100644 --- a/besu/src/main/java/org/hyperledger/besu/services/PermissioningServiceImpl.java +++ b/besu/src/main/java/org/hyperledger/besu/services/PermissioningServiceImpl.java @@ -14,7 +14,7 @@ */ package org.hyperledger.besu.services; -import org.hyperledger.besu.ethereum.core.Transaction; +import org.hyperledger.besu.datatypes.Transaction; import org.hyperledger.besu.plugin.services.PermissioningService; import org.hyperledger.besu.plugin.services.permissioning.NodeConnectionPermissioningProvider; import org.hyperledger.besu.plugin.services.permissioning.NodeMessagePermissioningProvider; diff --git a/ethereum/permissioning/src/main/java/org/hyperledger/besu/ethereum/permissioning/AccountLocalConfigPermissioningController.java b/ethereum/permissioning/src/main/java/org/hyperledger/besu/ethereum/permissioning/AccountLocalConfigPermissioningController.java index 690f18057ad..230b0164e02 100644 --- a/ethereum/permissioning/src/main/java/org/hyperledger/besu/ethereum/permissioning/AccountLocalConfigPermissioningController.java +++ b/ethereum/permissioning/src/main/java/org/hyperledger/besu/ethereum/permissioning/AccountLocalConfigPermissioningController.java @@ -16,7 +16,7 @@ import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Hash; -import org.hyperledger.besu.ethereum.core.Transaction; +import org.hyperledger.besu.datatypes.Transaction; import org.hyperledger.besu.ethereum.permissioning.AllowlistPersistor.ALLOWLIST_TYPE; import org.hyperledger.besu.plugin.services.permissioning.TransactionPermissioningProvider; import org.hyperledger.besu.metrics.BesuMetricCategory; diff --git a/ethereum/permissioning/src/main/java/org/hyperledger/besu/ethereum/permissioning/TransactionSmartContractPermissioningController.java b/ethereum/permissioning/src/main/java/org/hyperledger/besu/ethereum/permissioning/TransactionSmartContractPermissioningController.java index e26cc4367f7..1dd26185eb6 100644 --- a/ethereum/permissioning/src/main/java/org/hyperledger/besu/ethereum/permissioning/TransactionSmartContractPermissioningController.java +++ b/ethereum/permissioning/src/main/java/org/hyperledger/besu/ethereum/permissioning/TransactionSmartContractPermissioningController.java @@ -19,7 +19,8 @@ import org.hyperledger.besu.crypto.Hash; import org.hyperledger.besu.datatypes.Address; -import org.hyperledger.besu.ethereum.core.Transaction; +import org.hyperledger.besu.datatypes.Quantity; +import org.hyperledger.besu.datatypes.Transaction; import org.hyperledger.besu.plugin.services.permissioning.TransactionPermissioningProvider; import org.hyperledger.besu.ethereum.transaction.CallParameter; import org.hyperledger.besu.ethereum.transaction.TransactionSimulator; @@ -28,6 +29,7 @@ import org.hyperledger.besu.plugin.services.MetricsSystem; import org.hyperledger.besu.plugin.services.metrics.Counter; +import java.math.BigInteger; import java.util.Optional; import org.apache.tuweni.bytes.Bytes; @@ -195,10 +197,13 @@ public static Bytes createPayload(final Bytes signature, final Transaction trans private static Bytes encodeTransaction(final Transaction transaction) { return Bytes.concatenate( encodeAddress(transaction.getSender()), - encodeAddress(transaction.getTo()), - transaction.getValue(), - transaction.getGasPrice().map(BaseUInt256Value::toBytes).orElse(Bytes32.ZERO), - encodeLong(transaction.getGasLimit()), + encodeAddress(transaction.getTo().map(Address.class::cast)), + convertQuantityToBytes(transaction.getValue()), + transaction.getGasPrice() + .map(price -> (BaseUInt256Value) price) + .map(BaseUInt256Value::toBytes) + .orElse(Bytes32.ZERO), + encodeLong(transaction.getGasLimit()), encodeBytes(transaction.getPayload())); } @@ -231,4 +236,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(Quantity quantity) { + if (quantity == null) { + return Bytes32.ZERO; + } + if (quantity instanceof BaseUInt256Value) { + return ((BaseUInt256Value) quantity).toBytes(); + } + BigInteger value = quantity.getAsBigInteger(); + return Bytes.wrap(value.toByteArray()); + } } diff --git a/plugin-api/build.gradle b/plugin-api/build.gradle index 3dd64323219..698439d8d75 100644 --- a/plugin-api/build.gradle +++ b/plugin-api/build.gradle @@ -71,7 +71,7 @@ Calculated : ${currentHash} tasks.register('checkAPIChanges', FileStateChecker) { description = "Checks that the API for the Plugin-API project does not change without deliberate thought" files = sourceSets.main.allJava.files - knownHash = 'rJfdsomLThb+igDcRPJhifZtLURQlFPqvvL9qtFxXHs=' + knownHash = 'aXMHjSFzjqAXM5dOtJZH+V1dkO065GwYFBcTACFV86A=' } check.dependsOn('checkAPIChanges') diff --git a/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/permissioning/TransactionPermissioningProvider.java b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/permissioning/TransactionPermissioningProvider.java index 7498615fc8c..83f5a818447 100644 --- a/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/permissioning/TransactionPermissioningProvider.java +++ b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/permissioning/TransactionPermissioningProvider.java @@ -1,6 +1,6 @@ package org.hyperledger.besu.plugin.services.permissioning; -import org.hyperledger.besu.ethereum.core.Transaction; +import org.hyperledger.besu.datatypes.Transaction; @FunctionalInterface public interface TransactionPermissioningProvider { From 5d815c25e8521d1dc3cff5c7be7881f9083c5de9 Mon Sep 17 00:00:00 2001 From: vaidikcode Date: Tue, 10 Dec 2024 14:59:45 +0530 Subject: [PATCH 14/18] spotless Signed-off-by: vaidikcode --- .../plugins/TestPermissioningPlugin.java | 19 +++++++++---------- .../plugins/PermissioningPluginTest.java | 4 ++-- .../services/PermissioningServiceImpl.java | 3 ++- ...untLocalConfigPermissioningController.java | 2 +- ...nSmartContractPermissioningController.java | 15 ++++++++------- .../plugin/services/PermissioningService.java | 2 +- .../TransactionPermissioningProvider.java | 16 +++++++++++++++- 7 files changed, 38 insertions(+), 23 deletions(-) diff --git a/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/TestPermissioningPlugin.java b/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/TestPermissioningPlugin.java index 967f03a58b8..88541c5a101 100644 --- a/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/TestPermissioningPlugin.java +++ b/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/TestPermissioningPlugin.java @@ -19,7 +19,6 @@ import org.hyperledger.besu.plugin.services.PermissioningService; import org.hyperledger.besu.plugin.services.PicoCLIOptions; - import com.google.auto.service.AutoService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -78,15 +77,15 @@ public void beforeExternalServices() { }); service.registerTransactionPermissioningProvider( - transaction -> { - long configuredGasLimitThreshold = 12000L; - long gasLimit = transaction.getGasLimit(); - LOG.info("Transaction gas limit: {} | Configured threshold: {} ", gasLimit, configuredGasLimitThreshold); - return gasLimit > configuredGasLimitThreshold; - } - ); - - + transaction -> { + long configuredGasLimitThreshold = 12000L; + long gasLimit = transaction.getGasLimit(); + LOG.info( + "Transaction gas limit: {} | Configured threshold: {} ", + gasLimit, + configuredGasLimitThreshold); + return gasLimit > configuredGasLimitThreshold; + }); } } diff --git a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/plugins/PermissioningPluginTest.java b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/plugins/PermissioningPluginTest.java index 03fbb64743f..3825e7b31cf 100644 --- a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/plugins/PermissioningPluginTest.java +++ b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/plugins/PermissioningPluginTest.java @@ -14,6 +14,8 @@ */ package org.hyperledger.besu.tests.acceptance.plugins; +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; + import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.tests.acceptance.dsl.AcceptanceTestBase; import org.hyperledger.besu.tests.acceptance.dsl.account.Account; @@ -27,8 +29,6 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static org.assertj.core.api.AssertionsForClassTypes.assertThat; - public class PermissioningPluginTest extends AcceptanceTestBase { private BesuNode minerNode; diff --git a/besu/src/main/java/org/hyperledger/besu/services/PermissioningServiceImpl.java b/besu/src/main/java/org/hyperledger/besu/services/PermissioningServiceImpl.java index 6c3efa30c1c..ada4cb4c39f 100644 --- a/besu/src/main/java/org/hyperledger/besu/services/PermissioningServiceImpl.java +++ b/besu/src/main/java/org/hyperledger/besu/services/PermissioningServiceImpl.java @@ -34,7 +34,8 @@ public class PermissioningServiceImpl implements PermissioningService { private final List connectionPermissioningProviders = Lists.newArrayList(); - private final List transactionPermissioningProviders = new ArrayList<>(); + private final List transactionPermissioningProviders = + new ArrayList<>(); /** Default Constructor. */ @Inject diff --git a/ethereum/permissioning/src/main/java/org/hyperledger/besu/ethereum/permissioning/AccountLocalConfigPermissioningController.java b/ethereum/permissioning/src/main/java/org/hyperledger/besu/ethereum/permissioning/AccountLocalConfigPermissioningController.java index 230b0164e02..0ac12fe4543 100644 --- a/ethereum/permissioning/src/main/java/org/hyperledger/besu/ethereum/permissioning/AccountLocalConfigPermissioningController.java +++ b/ethereum/permissioning/src/main/java/org/hyperledger/besu/ethereum/permissioning/AccountLocalConfigPermissioningController.java @@ -18,10 +18,10 @@ import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.datatypes.Transaction; import org.hyperledger.besu.ethereum.permissioning.AllowlistPersistor.ALLOWLIST_TYPE; -import org.hyperledger.besu.plugin.services.permissioning.TransactionPermissioningProvider; import org.hyperledger.besu.metrics.BesuMetricCategory; import org.hyperledger.besu.plugin.services.MetricsSystem; import org.hyperledger.besu.plugin.services.metrics.Counter; +import org.hyperledger.besu.plugin.services.permissioning.TransactionPermissioningProvider; import java.io.IOException; import java.util.ArrayList; diff --git a/ethereum/permissioning/src/main/java/org/hyperledger/besu/ethereum/permissioning/TransactionSmartContractPermissioningController.java b/ethereum/permissioning/src/main/java/org/hyperledger/besu/ethereum/permissioning/TransactionSmartContractPermissioningController.java index 1dd26185eb6..5fa3dda5043 100644 --- a/ethereum/permissioning/src/main/java/org/hyperledger/besu/ethereum/permissioning/TransactionSmartContractPermissioningController.java +++ b/ethereum/permissioning/src/main/java/org/hyperledger/besu/ethereum/permissioning/TransactionSmartContractPermissioningController.java @@ -21,13 +21,13 @@ import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Quantity; import org.hyperledger.besu.datatypes.Transaction; -import org.hyperledger.besu.plugin.services.permissioning.TransactionPermissioningProvider; import org.hyperledger.besu.ethereum.transaction.CallParameter; import org.hyperledger.besu.ethereum.transaction.TransactionSimulator; import org.hyperledger.besu.ethereum.transaction.TransactionSimulatorResult; import org.hyperledger.besu.metrics.BesuMetricCategory; import org.hyperledger.besu.plugin.services.MetricsSystem; import org.hyperledger.besu.plugin.services.metrics.Counter; +import org.hyperledger.besu.plugin.services.permissioning.TransactionPermissioningProvider; import java.math.BigInteger; import java.util.Optional; @@ -197,13 +197,14 @@ public static Bytes createPayload(final Bytes signature, final Transaction trans private static Bytes encodeTransaction(final Transaction transaction) { return Bytes.concatenate( encodeAddress(transaction.getSender()), - encodeAddress(transaction.getTo().map(Address.class::cast)), + encodeAddress(transaction.getTo().map(Address.class::cast)), convertQuantityToBytes(transaction.getValue()), - transaction.getGasPrice() - .map(price -> (BaseUInt256Value) price) - .map(BaseUInt256Value::toBytes) - .orElse(Bytes32.ZERO), - encodeLong(transaction.getGasLimit()), + transaction + .getGasPrice() + .map(price -> (BaseUInt256Value) price) + .map(BaseUInt256Value::toBytes) + .orElse(Bytes32.ZERO), + encodeLong(transaction.getGasLimit()), encodeBytes(transaction.getPayload())); } diff --git a/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/PermissioningService.java b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/PermissioningService.java index 8a13dd7c728..5e0b756f491 100644 --- a/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/PermissioningService.java +++ b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/PermissioningService.java @@ -14,9 +14,9 @@ */ package org.hyperledger.besu.plugin.services; -import org.hyperledger.besu.plugin.services.permissioning.TransactionPermissioningProvider; import org.hyperledger.besu.plugin.services.permissioning.NodeConnectionPermissioningProvider; import org.hyperledger.besu.plugin.services.permissioning.NodeMessagePermissioningProvider; +import org.hyperledger.besu.plugin.services.permissioning.TransactionPermissioningProvider; /** * This service allows plugins to decide who you should connect to and what you should send them. diff --git a/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/permissioning/TransactionPermissioningProvider.java b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/permissioning/TransactionPermissioningProvider.java index 83f5a818447..f09f6487c39 100644 --- a/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/permissioning/TransactionPermissioningProvider.java +++ b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/permissioning/TransactionPermissioningProvider.java @@ -1,8 +1,22 @@ +/* + * Copyright contributors to Besu. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ package org.hyperledger.besu.plugin.services.permissioning; import org.hyperledger.besu.datatypes.Transaction; @FunctionalInterface public interface TransactionPermissioningProvider { - boolean isPermitted(final Transaction transaction); + boolean isPermitted(final Transaction transaction); } From 80c832c1c73cc47e83a92e6efc3515a970630ea9 Mon Sep 17 00:00:00 2001 From: vaidikcode Date: Wed, 11 Dec 2024 15:01:32 +0530 Subject: [PATCH 15/18] compile error fix Signed-off-by: vaidikcode --- .../hyperledger/besu/services/PermissioningServiceImpl.java | 5 +++-- .../TransactionSmartContractPermissioningController.java | 4 ++-- .../besu/plugin/services/PermissioningService.java | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/besu/src/main/java/org/hyperledger/besu/services/PermissioningServiceImpl.java b/besu/src/main/java/org/hyperledger/besu/services/PermissioningServiceImpl.java index ada4cb4c39f..3970ebb671c 100644 --- a/besu/src/main/java/org/hyperledger/besu/services/PermissioningServiceImpl.java +++ b/besu/src/main/java/org/hyperledger/besu/services/PermissioningServiceImpl.java @@ -48,7 +48,8 @@ public void registerNodePermissioningProvider( } @Override - public void registerTransactionPermissioningProvider(TransactionPermissioningProvider provider) { + public void registerTransactionPermissioningProvider( + final TransactionPermissioningProvider provider) { transactionPermissioningProviders.add(provider); LOG.info("Registered new transaction permissioning provider."); } @@ -85,7 +86,7 @@ public List getMessagePermissioningProviders() * * @return whether the transaction is permitted */ - public boolean isTransactionPermitted(Transaction transaction) { + public boolean isTransactionPermitted(final Transaction transaction) { for (TransactionPermissioningProvider provider : transactionPermissioningProviders) { if (!provider.isPermitted(transaction)) { LOG.debug("Transaction {} not permitted by one of the providers.", transaction.getHash()); diff --git a/ethereum/permissioning/src/main/java/org/hyperledger/besu/ethereum/permissioning/TransactionSmartContractPermissioningController.java b/ethereum/permissioning/src/main/java/org/hyperledger/besu/ethereum/permissioning/TransactionSmartContractPermissioningController.java index 5fa3dda5043..60b1838ab3b 100644 --- a/ethereum/permissioning/src/main/java/org/hyperledger/besu/ethereum/permissioning/TransactionSmartContractPermissioningController.java +++ b/ethereum/permissioning/src/main/java/org/hyperledger/besu/ethereum/permissioning/TransactionSmartContractPermissioningController.java @@ -201,7 +201,7 @@ private static Bytes encodeTransaction(final Transaction transaction) { convertQuantityToBytes(transaction.getValue()), transaction .getGasPrice() - .map(price -> (BaseUInt256Value) price) + .map(price -> (BaseUInt256Value) price) .map(BaseUInt256Value::toBytes) .orElse(Bytes32.ZERO), encodeLong(transaction.getGasLimit()), @@ -239,7 +239,7 @@ private static Bytes encodeBytes(final Bytes value) { } // Convert the Quantity value to Bytes - private static Bytes convertQuantityToBytes(Quantity quantity) { + private static Bytes convertQuantityToBytes(final Quantity quantity) { if (quantity == null) { return Bytes32.ZERO; } diff --git a/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/PermissioningService.java b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/PermissioningService.java index 5e0b756f491..061a9e5cc1d 100644 --- a/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/PermissioningService.java +++ b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/PermissioningService.java @@ -44,7 +44,7 @@ public interface PermissioningService extends BesuService { * * @param provider The provider to register */ - void registerTransactionPermissioningProvider(TransactionPermissioningProvider provider); + void registerTransactionPermissioningProvider(final TransactionPermissioningProvider provider); /** * Registers a callback to allow the interception of a devp2p message sending request From 0b23b89ebddde00a1a61fa1c4cd18be36c987f48 Mon Sep 17 00:00:00 2001 From: vaidikcode Date: Thu, 12 Dec 2024 02:54:04 +0530 Subject: [PATCH 16/18] minor fix Signed-off-by: vaidikcode --- plugin-api/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin-api/build.gradle b/plugin-api/build.gradle index 698439d8d75..04f3546b464 100644 --- a/plugin-api/build.gradle +++ b/plugin-api/build.gradle @@ -71,7 +71,7 @@ Calculated : ${currentHash} tasks.register('checkAPIChanges', FileStateChecker) { description = "Checks that the API for the Plugin-API project does not change without deliberate thought" files = sourceSets.main.allJava.files - knownHash = 'aXMHjSFzjqAXM5dOtJZH+V1dkO065GwYFBcTACFV86A=' + knownHash = 'ILrmIl1hU61dFKgFPIvxIJYVLAbIOfX62SotTY2pWnA=' } check.dependsOn('checkAPIChanges') From 040857a8585f5e741f441e24b7246b1edb668ad5 Mon Sep 17 00:00:00 2001 From: vaidikcode Date: Thu, 12 Dec 2024 03:00:10 +0530 Subject: [PATCH 17/18] minor fix Signed-off-by: vaidikcode --- .../besu/tests/acceptance/plugins/PermissioningPluginTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/plugins/PermissioningPluginTest.java b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/plugins/PermissioningPluginTest.java index 3825e7b31cf..a3fae4e3a19 100644 --- a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/plugins/PermissioningPluginTest.java +++ b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/plugins/PermissioningPluginTest.java @@ -109,7 +109,7 @@ public void testGasLimitLogic() { assertThat(isTransactionPermitted).isTrue(); } - private boolean checkTransactionGasLimit(long gasLimit) { + private boolean checkTransactionGasLimit(final long gasLimit) { if (gasLimit > GAS_LIMIT_THRESHOLD) { return true; } else { From a037c07c6657169a24975ef4d50335d3ff28c181 Mon Sep 17 00:00:00 2001 From: Sally MacFarlane Date: Thu, 12 Dec 2024 09:18:11 +1000 Subject: [PATCH 18/18] final Signed-off-by: Sally MacFarlane --- .../besu/tests/acceptance/plugins/PermissioningPluginTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/plugins/PermissioningPluginTest.java b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/plugins/PermissioningPluginTest.java index 3825e7b31cf..a3fae4e3a19 100644 --- a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/plugins/PermissioningPluginTest.java +++ b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/plugins/PermissioningPluginTest.java @@ -109,7 +109,7 @@ public void testGasLimitLogic() { assertThat(isTransactionPermitted).isTrue(); } - private boolean checkTransactionGasLimit(long gasLimit) { + private boolean checkTransactionGasLimit(final long gasLimit) { if (gasLimit > GAS_LIMIT_THRESHOLD) { return true; } else {