From a25f5bb9595a089c921483b27db73e2bd1936026 Mon Sep 17 00:00:00 2001 From: Sally MacFarlane Date: Tue, 17 Sep 2024 12:26:32 +1000 Subject: [PATCH 1/9] draft Signed-off-by: Sally MacFarlane --- .../TransactionPoolDenyListReloadTest.java | 125 ++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100644 acceptance-tests/src/test/java/linea/plugin/acc/test/TransactionPoolDenyListReloadTest.java diff --git a/acceptance-tests/src/test/java/linea/plugin/acc/test/TransactionPoolDenyListReloadTest.java b/acceptance-tests/src/test/java/linea/plugin/acc/test/TransactionPoolDenyListReloadTest.java new file mode 100644 index 00000000..057a9d73 --- /dev/null +++ b/acceptance-tests/src/test/java/linea/plugin/acc/test/TransactionPoolDenyListReloadTest.java @@ -0,0 +1,125 @@ +/* + * Copyright Consensys Software Inc. + * + * 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 linea.plugin.acc.test; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.math.BigInteger; +import java.nio.file.Path; +import java.util.List; + +import org.hyperledger.besu.tests.acceptance.dsl.account.Accounts; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; +import org.web3j.crypto.Credentials; +import org.web3j.protocol.Web3j; +import org.web3j.protocol.core.methods.response.EthSendTransaction; +import org.web3j.tx.RawTransactionManager; +import org.web3j.utils.Convert; + +public class TransactionPoolDenyListReloadTest extends LineaPluginTestBase { + + private static final BigInteger GAS_PRICE = Convert.toWei("20", Convert.Unit.GWEI).toBigInteger(); + private static final BigInteger GAS_LIMIT = BigInteger.valueOf(210000); + private static final BigInteger VALUE = BigInteger.ONE; // 1 wei + + final Credentials notDenied = Credentials.create(Accounts.GENESIS_ACCOUNT_ONE_PRIVATE_KEY); + final Credentials denied = Credentials.create(Accounts.GENESIS_ACCOUNT_TWO_PRIVATE_KEY); + + @TempDir static Path tempDir; + static Path tempDenyList; + + @BeforeEach + public void setUp() throws Exception { + tempDenyList = tempDir.resolve("denyList.txt"); + } + + @Override + public List getTestCliOptions() { + return new TestCommandLineOptionsBuilder() + .set("--plugin-linea-deny-list-path=", tempDenyList.toString()) + .build(); + } + + @Test + public void emptyDenyList() throws Exception { + final Web3j miner = minerNode.nodeRequests().eth(); + + RawTransactionManager transactionManager = new RawTransactionManager(miner, denied, CHAIN_ID); + EthSendTransaction transactionResponse = + transactionManager.sendTransaction(GAS_PRICE, GAS_LIMIT, notDenied.getAddress(), "", VALUE); + assertThat(transactionResponse.getTransactionHash()).isNotNull(); + assertThat(transactionResponse.getError().getMessage()).isNull(); + } + + @Test + public void senderOnDenyListThenRemoved_CanAddTransactionToPool() throws Exception { + final Web3j miner = minerNode.nodeRequests().eth(); + + RawTransactionManager transactionManager = new RawTransactionManager(miner, denied, CHAIN_ID); + EthSendTransaction transactionResponse = + transactionManager.sendTransaction(GAS_PRICE, GAS_LIMIT, notDenied.getAddress(), "", VALUE); + + assertThat(transactionResponse.getTransactionHash()).isNull(); + assertThat(transactionResponse.getError().getMessage()) + .isEqualTo( + "sender 0x627306090abab3a6e1400e9345bc60c78a8bef57 is blocked as appearing on the SDN or other legally prohibited list"); + + // TODO then remove that account from denyList.txt + // TODO assert that denyList.txt is empty + // TODO assert that that sender can now send transactions. + + EthSendTransaction transactionResponse2 = + transactionManager.sendTransaction(GAS_PRICE, GAS_LIMIT, notDenied.getAddress(), "", VALUE); + + assertThat(transactionResponse2.getTransactionHash()).isNotNull(); + assertThat(transactionResponse2.getError().getMessage()).isNull(); + } + + @Test + public void transactionWithRecipientOnDenyListCannotBeAddedToPool() throws Exception { + final Web3j miner = minerNode.nodeRequests().eth(); + + RawTransactionManager transactionManager = + new RawTransactionManager(miner, notDenied, CHAIN_ID); + EthSendTransaction transactionResponse = + transactionManager.sendTransaction(GAS_PRICE, GAS_LIMIT, denied.getAddress(), "", VALUE); + + assertThat(transactionResponse.getTransactionHash()).isNull(); + assertThat(transactionResponse.getError().getMessage()) + .isEqualTo( + "recipient 0x627306090abab3a6e1400e9345bc60c78a8bef57 is blocked as appearing on the SDN or other legally prohibited list"); + } + + @Test + public void transactionCallingContractOnDenyListCannotBeAddedToPool() throws Exception { + final Web3j miner = minerNode.nodeRequests().eth(); + + RawTransactionManager transactionManager = + new RawTransactionManager(miner, notDenied, CHAIN_ID); + EthSendTransaction transactionResponse = + transactionManager.sendTransaction( + GAS_PRICE, + GAS_LIMIT, + "0x000000000000000000000000000000000000000a", + "0xdeadbeef", + VALUE); + + assertThat(transactionResponse.getTransactionHash()).isNull(); + assertThat(transactionResponse.getError().getMessage()) + .isEqualTo("destination address is a precompile address and cannot receive transactions"); + } +} From 4196abeabb131af4cedf47c1ef0467483463369c Mon Sep 17 00:00:00 2001 From: Sally MacFarlane Date: Fri, 20 Sep 2024 12:13:22 +1000 Subject: [PATCH 2/9] draft Signed-off-by: Sally MacFarlane --- .../acc/test/TransactionPoolDenyListReloadTest.java | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/acceptance-tests/src/test/java/linea/plugin/acc/test/TransactionPoolDenyListReloadTest.java b/acceptance-tests/src/test/java/linea/plugin/acc/test/TransactionPoolDenyListReloadTest.java index 057a9d73..a2cc3a18 100644 --- a/acceptance-tests/src/test/java/linea/plugin/acc/test/TransactionPoolDenyListReloadTest.java +++ b/acceptance-tests/src/test/java/linea/plugin/acc/test/TransactionPoolDenyListReloadTest.java @@ -21,7 +21,6 @@ import java.util.List; import org.hyperledger.besu.tests.acceptance.dsl.account.Accounts; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; import org.web3j.crypto.Credentials; @@ -40,15 +39,11 @@ public class TransactionPoolDenyListReloadTest extends LineaPluginTestBase { final Credentials denied = Credentials.create(Accounts.GENESIS_ACCOUNT_TWO_PRIVATE_KEY); @TempDir static Path tempDir; - static Path tempDenyList; - - @BeforeEach - public void setUp() throws Exception { - tempDenyList = tempDir.resolve("denyList.txt"); - } + static Path tempDenyList ; @Override public List getTestCliOptions() { + tempDenyList = tempDir.resolve("denyList.txt"); return new TestCommandLineOptionsBuilder() .set("--plugin-linea-deny-list-path=", tempDenyList.toString()) .build(); @@ -62,7 +57,7 @@ public void emptyDenyList() throws Exception { EthSendTransaction transactionResponse = transactionManager.sendTransaction(GAS_PRICE, GAS_LIMIT, notDenied.getAddress(), "", VALUE); assertThat(transactionResponse.getTransactionHash()).isNotNull(); - assertThat(transactionResponse.getError().getMessage()).isNull(); + assertThat(transactionResponse.getError()).isNull(); } @Test From 188cd8937cdc6cbb49dc7ac285fe970828f7b3ba Mon Sep 17 00:00:00 2001 From: Sally MacFarlane Date: Sun, 22 Sep 2024 08:21:02 +1000 Subject: [PATCH 3/9] draft implementation of reload Signed-off-by: Sally MacFarlane --- .../TransactionPoolDenyListReloadTest.java | 86 ++++++++++++++++--- .../LineaTransactionPoolValidatorPlugin.java | 12 +++ 2 files changed, 87 insertions(+), 11 deletions(-) diff --git a/acceptance-tests/src/test/java/linea/plugin/acc/test/TransactionPoolDenyListReloadTest.java b/acceptance-tests/src/test/java/linea/plugin/acc/test/TransactionPoolDenyListReloadTest.java index a2cc3a18..824065d3 100644 --- a/acceptance-tests/src/test/java/linea/plugin/acc/test/TransactionPoolDenyListReloadTest.java +++ b/acceptance-tests/src/test/java/linea/plugin/acc/test/TransactionPoolDenyListReloadTest.java @@ -16,15 +16,20 @@ import static org.assertj.core.api.Assertions.assertThat; +import java.io.IOException; import java.math.BigInteger; +import java.nio.file.Files; import java.nio.file.Path; import java.util.List; import org.hyperledger.besu.tests.acceptance.dsl.account.Accounts; +import org.hyperledger.besu.tests.acceptance.dsl.transaction.NodeRequests; +import org.hyperledger.besu.tests.acceptance.dsl.transaction.Transaction; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; import org.web3j.crypto.Credentials; import org.web3j.protocol.Web3j; +import org.web3j.protocol.core.Request; import org.web3j.protocol.core.methods.response.EthSendTransaction; import org.web3j.tx.RawTransactionManager; import org.web3j.utils.Convert; @@ -36,7 +41,7 @@ public class TransactionPoolDenyListReloadTest extends LineaPluginTestBase { private static final BigInteger VALUE = BigInteger.ONE; // 1 wei final Credentials notDenied = Credentials.create(Accounts.GENESIS_ACCOUNT_ONE_PRIVATE_KEY); - final Credentials denied = Credentials.create(Accounts.GENESIS_ACCOUNT_TWO_PRIVATE_KEY); + final Credentials willbeDenied = Credentials.create(Accounts.GENESIS_ACCOUNT_TWO_PRIVATE_KEY); @TempDir static Path tempDir; static Path tempDenyList ; @@ -53,18 +58,27 @@ public List getTestCliOptions() { public void emptyDenyList() throws Exception { final Web3j miner = minerNode.nodeRequests().eth(); - RawTransactionManager transactionManager = new RawTransactionManager(miner, denied, CHAIN_ID); - EthSendTransaction transactionResponse = - transactionManager.sendTransaction(GAS_PRICE, GAS_LIMIT, notDenied.getAddress(), "", VALUE); - assertThat(transactionResponse.getTransactionHash()).isNotNull(); - assertThat(transactionResponse.getError()).isNull(); + RawTransactionManager transactionManager = new RawTransactionManager(miner, willbeDenied, CHAIN_ID); + assertAddressAllowed(transactionManager,willbeDenied.getAddress() ); } @Test - public void senderOnDenyListThenRemoved_CanAddTransactionToPool() throws Exception { + public void emptyDenyList_thenDenySender_cannotAddTxToPool() throws Exception { final Web3j miner = minerNode.nodeRequests().eth(); + RawTransactionManager transactionManager = new RawTransactionManager(miner, willbeDenied, CHAIN_ID); + + assertAddressAllowed(transactionManager, willbeDenied.getAddress()); + addAddressToDenyList(willbeDenied.getAddress()); + + reloadPluginConfig(); + + assertAddressNotAllowed(transactionManager, willbeDenied.getAddress()); + } - RawTransactionManager transactionManager = new RawTransactionManager(miner, denied, CHAIN_ID); + public void senderOnDenyListThenRemoved_canAddTxToPool() throws Exception { + final Web3j miner = minerNode.nodeRequests().eth(); + + RawTransactionManager transactionManager = new RawTransactionManager(miner, willbeDenied, CHAIN_ID); EthSendTransaction transactionResponse = transactionManager.sendTransaction(GAS_PRICE, GAS_LIMIT, notDenied.getAddress(), "", VALUE); @@ -84,14 +98,13 @@ public void senderOnDenyListThenRemoved_CanAddTransactionToPool() throws Excepti assertThat(transactionResponse2.getError().getMessage()).isNull(); } - @Test public void transactionWithRecipientOnDenyListCannotBeAddedToPool() throws Exception { final Web3j miner = minerNode.nodeRequests().eth(); RawTransactionManager transactionManager = new RawTransactionManager(miner, notDenied, CHAIN_ID); EthSendTransaction transactionResponse = - transactionManager.sendTransaction(GAS_PRICE, GAS_LIMIT, denied.getAddress(), "", VALUE); + transactionManager.sendTransaction(GAS_PRICE, GAS_LIMIT, willbeDenied.getAddress(), "", VALUE); assertThat(transactionResponse.getTransactionHash()).isNull(); assertThat(transactionResponse.getError().getMessage()) @@ -99,7 +112,6 @@ public void transactionWithRecipientOnDenyListCannotBeAddedToPool() throws Excep "recipient 0x627306090abab3a6e1400e9345bc60c78a8bef57 is blocked as appearing on the SDN or other legally prohibited list"); } - @Test public void transactionCallingContractOnDenyListCannotBeAddedToPool() throws Exception { final Web3j miner = minerNode.nodeRequests().eth(); @@ -117,4 +129,56 @@ public void transactionCallingContractOnDenyListCannotBeAddedToPool() throws Exc assertThat(transactionResponse.getError().getMessage()) .isEqualTo("destination address is a precompile address and cannot receive transactions"); } + + private void addAddressToDenyList(String address) throws IOException { + Files.writeString(tempDenyList, address); + } + + private void assertAddressAllowed(RawTransactionManager transactionManager, String address) throws IOException { + EthSendTransaction transactionResponse = + transactionManager.sendTransaction(GAS_PRICE, GAS_LIMIT, address, "", VALUE); + assertThat(transactionResponse.getTransactionHash()).isNotNull(); + assertThat(transactionResponse.getError()).isNull(); + } + + private void assertAddressNotAllowed(RawTransactionManager transactionManager, String address) throws IOException { + EthSendTransaction transactionResponse = + transactionManager.sendTransaction(GAS_PRICE, GAS_LIMIT, address, "", VALUE); + + assertThat(transactionResponse.getTransactionHash()).isNull(); + assertThat(transactionResponse.getError().getMessage()) + .isEqualTo( + "recipient "+ address + " is blocked as appearing on the SDN or other legally prohibited list"); + } + + private void reloadPluginConfig() { + final var reqLinea = new ReloadPluginConfigRequest(); +// System.out.println("88888888"+reqLinea); + final var respLinea = reqLinea.execute(minerNode.nodeRequests()); +// System.out.println("88888888"+respLinea); + assertThat(respLinea.booleanValue()).isTrue(); + } + + static class ReloadPluginConfigRequest implements Transaction { + + public ReloadPluginConfigRequest() { + } + + @Override + public Boolean execute(final NodeRequests nodeRequests) { + try { + return new Request<>( + "plugins_reloadPluginConfig", + List.of(), + nodeRequests.getWeb3jService(), + ReloadPluginConfigResponse.class) + .send() + .getResult(); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + } + + static class ReloadPluginConfigResponse extends org.web3j.protocol.core.Response {} } diff --git a/sequencer/src/main/java/net/consensys/linea/sequencer/txpoolvalidation/LineaTransactionPoolValidatorPlugin.java b/sequencer/src/main/java/net/consensys/linea/sequencer/txpoolvalidation/LineaTransactionPoolValidatorPlugin.java index a0b28aa3..29803524 100644 --- a/sequencer/src/main/java/net/consensys/linea/sequencer/txpoolvalidation/LineaTransactionPoolValidatorPlugin.java +++ b/sequencer/src/main/java/net/consensys/linea/sequencer/txpoolvalidation/LineaTransactionPoolValidatorPlugin.java @@ -22,6 +22,7 @@ import java.nio.file.Path; import java.util.Optional; import java.util.Set; +import java.util.concurrent.CompletableFuture; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -94,6 +95,10 @@ public void doRegister(final BesuContext context) { @Override public void start() { super.start(); + loadDenyListAndRegisterPluginTxValidatorFactory(); + } + + private void loadDenyListAndRegisterPluginTxValidatorFactory() { try (Stream lines = Files.lines( Path.of(new File(transactionPoolValidatorConfiguration().denyListPath()).toURI()))) { @@ -115,4 +120,11 @@ public void start() { throw new RuntimeException(e); } } + + @Override + public CompletableFuture reloadConfiguration() { + loadDenyListAndRegisterPluginTxValidatorFactory(); + return CompletableFuture.completedFuture(null); + } + } From 3e6178f615b83b72c082dbe834ec358111666a22 Mon Sep 17 00:00:00 2001 From: Sally MacFarlane Date: Sun, 22 Sep 2024 10:55:19 +1000 Subject: [PATCH 4/9] cleanup Signed-off-by: Sally MacFarlane --- .../TransactionPoolDenyListReloadTest.java | 68 ++----------------- 1 file changed, 7 insertions(+), 61 deletions(-) diff --git a/acceptance-tests/src/test/java/linea/plugin/acc/test/TransactionPoolDenyListReloadTest.java b/acceptance-tests/src/test/java/linea/plugin/acc/test/TransactionPoolDenyListReloadTest.java index 824065d3..3caf2346 100644 --- a/acceptance-tests/src/test/java/linea/plugin/acc/test/TransactionPoolDenyListReloadTest.java +++ b/acceptance-tests/src/test/java/linea/plugin/acc/test/TransactionPoolDenyListReloadTest.java @@ -68,80 +68,25 @@ public void emptyDenyList_thenDenySender_cannotAddTxToPool() throws Exception { RawTransactionManager transactionManager = new RawTransactionManager(miner, willbeDenied, CHAIN_ID); assertAddressAllowed(transactionManager, willbeDenied.getAddress()); - addAddressToDenyList(willbeDenied.getAddress()); + addAddressToDenyList(willbeDenied.getAddress()); reloadPluginConfig(); assertAddressNotAllowed(transactionManager, willbeDenied.getAddress()); } - public void senderOnDenyListThenRemoved_canAddTxToPool() throws Exception { - final Web3j miner = minerNode.nodeRequests().eth(); - - RawTransactionManager transactionManager = new RawTransactionManager(miner, willbeDenied, CHAIN_ID); - EthSendTransaction transactionResponse = - transactionManager.sendTransaction(GAS_PRICE, GAS_LIMIT, notDenied.getAddress(), "", VALUE); - - assertThat(transactionResponse.getTransactionHash()).isNull(); - assertThat(transactionResponse.getError().getMessage()) - .isEqualTo( - "sender 0x627306090abab3a6e1400e9345bc60c78a8bef57 is blocked as appearing on the SDN or other legally prohibited list"); - - // TODO then remove that account from denyList.txt - // TODO assert that denyList.txt is empty - // TODO assert that that sender can now send transactions. - - EthSendTransaction transactionResponse2 = - transactionManager.sendTransaction(GAS_PRICE, GAS_LIMIT, notDenied.getAddress(), "", VALUE); - - assertThat(transactionResponse2.getTransactionHash()).isNotNull(); - assertThat(transactionResponse2.getError().getMessage()).isNull(); - } - - public void transactionWithRecipientOnDenyListCannotBeAddedToPool() throws Exception { - final Web3j miner = minerNode.nodeRequests().eth(); - - RawTransactionManager transactionManager = - new RawTransactionManager(miner, notDenied, CHAIN_ID); - EthSendTransaction transactionResponse = - transactionManager.sendTransaction(GAS_PRICE, GAS_LIMIT, willbeDenied.getAddress(), "", VALUE); - - assertThat(transactionResponse.getTransactionHash()).isNull(); - assertThat(transactionResponse.getError().getMessage()) - .isEqualTo( - "recipient 0x627306090abab3a6e1400e9345bc60c78a8bef57 is blocked as appearing on the SDN or other legally prohibited list"); - } - - public void transactionCallingContractOnDenyListCannotBeAddedToPool() throws Exception { - final Web3j miner = minerNode.nodeRequests().eth(); - - RawTransactionManager transactionManager = - new RawTransactionManager(miner, notDenied, CHAIN_ID); - EthSendTransaction transactionResponse = - transactionManager.sendTransaction( - GAS_PRICE, - GAS_LIMIT, - "0x000000000000000000000000000000000000000a", - "0xdeadbeef", - VALUE); - - assertThat(transactionResponse.getTransactionHash()).isNull(); - assertThat(transactionResponse.getError().getMessage()) - .isEqualTo("destination address is a precompile address and cannot receive transactions"); - } - - private void addAddressToDenyList(String address) throws IOException { + private void addAddressToDenyList(final String address) throws IOException { Files.writeString(tempDenyList, address); } - private void assertAddressAllowed(RawTransactionManager transactionManager, String address) throws IOException { + private void assertAddressAllowed(final RawTransactionManager transactionManager, final String address) throws IOException { EthSendTransaction transactionResponse = transactionManager.sendTransaction(GAS_PRICE, GAS_LIMIT, address, "", VALUE); assertThat(transactionResponse.getTransactionHash()).isNotNull(); assertThat(transactionResponse.getError()).isNull(); } - private void assertAddressNotAllowed(RawTransactionManager transactionManager, String address) throws IOException { + private void assertAddressNotAllowed(final RawTransactionManager transactionManager, final String address) throws IOException { EthSendTransaction transactionResponse = transactionManager.sendTransaction(GAS_PRICE, GAS_LIMIT, address, "", VALUE); @@ -152,10 +97,11 @@ private void assertAddressNotAllowed(RawTransactionManager transactionManager, S } private void reloadPluginConfig() { + System.out.println("GOT HERE ******"); final var reqLinea = new ReloadPluginConfigRequest(); -// System.out.println("88888888"+reqLinea); + System.out.println("88888888"+reqLinea); final var respLinea = reqLinea.execute(minerNode.nodeRequests()); -// System.out.println("88888888"+respLinea); + System.out.println("88888888"+respLinea); assertThat(respLinea.booleanValue()).isTrue(); } From 7971dc2a0dd323b62578c78d19f50f2ea0a4089f Mon Sep 17 00:00:00 2001 From: Sally MacFarlane Date: Thu, 3 Oct 2024 11:54:05 +1000 Subject: [PATCH 5/9] formatting Signed-off-by: Sally MacFarlane --- .../TransactionPoolDenyListReloadTest.java | 37 +++++++++++-------- .../LineaTransactionPoolValidatorPlugin.java | 1 - 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/acceptance-tests/src/test/java/linea/plugin/acc/test/TransactionPoolDenyListReloadTest.java b/acceptance-tests/src/test/java/linea/plugin/acc/test/TransactionPoolDenyListReloadTest.java index 3caf2346..7b1770cb 100644 --- a/acceptance-tests/src/test/java/linea/plugin/acc/test/TransactionPoolDenyListReloadTest.java +++ b/acceptance-tests/src/test/java/linea/plugin/acc/test/TransactionPoolDenyListReloadTest.java @@ -44,7 +44,7 @@ public class TransactionPoolDenyListReloadTest extends LineaPluginTestBase { final Credentials willbeDenied = Credentials.create(Accounts.GENESIS_ACCOUNT_TWO_PRIVATE_KEY); @TempDir static Path tempDir; - static Path tempDenyList ; + static Path tempDenyList; @Override public List getTestCliOptions() { @@ -58,14 +58,16 @@ public List getTestCliOptions() { public void emptyDenyList() throws Exception { final Web3j miner = minerNode.nodeRequests().eth(); - RawTransactionManager transactionManager = new RawTransactionManager(miner, willbeDenied, CHAIN_ID); - assertAddressAllowed(transactionManager,willbeDenied.getAddress() ); + RawTransactionManager transactionManager = + new RawTransactionManager(miner, willbeDenied, CHAIN_ID); + assertAddressAllowed(transactionManager, willbeDenied.getAddress()); } @Test public void emptyDenyList_thenDenySender_cannotAddTxToPool() throws Exception { final Web3j miner = minerNode.nodeRequests().eth(); - RawTransactionManager transactionManager = new RawTransactionManager(miner, willbeDenied, CHAIN_ID); + RawTransactionManager transactionManager = + new RawTransactionManager(miner, willbeDenied, CHAIN_ID); assertAddressAllowed(transactionManager, willbeDenied.getAddress()); @@ -79,36 +81,39 @@ private void addAddressToDenyList(final String address) throws IOException { Files.writeString(tempDenyList, address); } - private void assertAddressAllowed(final RawTransactionManager transactionManager, final String address) throws IOException { + private void assertAddressAllowed( + final RawTransactionManager transactionManager, final String address) throws IOException { EthSendTransaction transactionResponse = - transactionManager.sendTransaction(GAS_PRICE, GAS_LIMIT, address, "", VALUE); + transactionManager.sendTransaction(GAS_PRICE, GAS_LIMIT, address, "", VALUE); assertThat(transactionResponse.getTransactionHash()).isNotNull(); assertThat(transactionResponse.getError()).isNull(); } - private void assertAddressNotAllowed(final RawTransactionManager transactionManager, final String address) throws IOException { + private void assertAddressNotAllowed( + final RawTransactionManager transactionManager, final String address) throws IOException { EthSendTransaction transactionResponse = - transactionManager.sendTransaction(GAS_PRICE, GAS_LIMIT, address, "", VALUE); + transactionManager.sendTransaction(GAS_PRICE, GAS_LIMIT, address, "", VALUE); assertThat(transactionResponse.getTransactionHash()).isNull(); assertThat(transactionResponse.getError().getMessage()) - .isEqualTo( - "recipient "+ address + " is blocked as appearing on the SDN or other legally prohibited list"); + .isEqualTo( + "recipient " + + address + + " is blocked as appearing on the SDN or other legally prohibited list"); } private void reloadPluginConfig() { System.out.println("GOT HERE ******"); final var reqLinea = new ReloadPluginConfigRequest(); - System.out.println("88888888"+reqLinea); + System.out.println("88888888" + reqLinea); final var respLinea = reqLinea.execute(minerNode.nodeRequests()); - System.out.println("88888888"+respLinea); + System.out.println("88888888" + respLinea); assertThat(respLinea.booleanValue()).isTrue(); } static class ReloadPluginConfigRequest implements Transaction { - public ReloadPluginConfigRequest() { - } + public ReloadPluginConfigRequest() {} @Override public Boolean execute(final NodeRequests nodeRequests) { @@ -118,8 +123,8 @@ public Boolean execute(final NodeRequests nodeRequests) { List.of(), nodeRequests.getWeb3jService(), ReloadPluginConfigResponse.class) - .send() - .getResult(); + .send() + .getResult(); } catch (IOException e) { throw new RuntimeException(e); } diff --git a/sequencer/src/main/java/net/consensys/linea/sequencer/txpoolvalidation/LineaTransactionPoolValidatorPlugin.java b/sequencer/src/main/java/net/consensys/linea/sequencer/txpoolvalidation/LineaTransactionPoolValidatorPlugin.java index 29803524..3c73b389 100644 --- a/sequencer/src/main/java/net/consensys/linea/sequencer/txpoolvalidation/LineaTransactionPoolValidatorPlugin.java +++ b/sequencer/src/main/java/net/consensys/linea/sequencer/txpoolvalidation/LineaTransactionPoolValidatorPlugin.java @@ -126,5 +126,4 @@ public CompletableFuture reloadConfiguration() { loadDenyListAndRegisterPluginTxValidatorFactory(); return CompletableFuture.completedFuture(null); } - } From 8182b42eec059925fea764000980df5d88376063 Mon Sep 17 00:00:00 2001 From: Sally MacFarlane Date: Mon, 14 Oct 2024 15:04:09 +1000 Subject: [PATCH 6/9] test passes Signed-off-by: Sally MacFarlane --- .../TransactionPoolDenyListReloadTest.java | 37 +++++++++++-------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/acceptance-tests/src/test/java/linea/plugin/acc/test/TransactionPoolDenyListReloadTest.java b/acceptance-tests/src/test/java/linea/plugin/acc/test/TransactionPoolDenyListReloadTest.java index 7b1770cb..8e0e68cf 100644 --- a/acceptance-tests/src/test/java/linea/plugin/acc/test/TransactionPoolDenyListReloadTest.java +++ b/acceptance-tests/src/test/java/linea/plugin/acc/test/TransactionPoolDenyListReloadTest.java @@ -41,7 +41,7 @@ public class TransactionPoolDenyListReloadTest extends LineaPluginTestBase { private static final BigInteger VALUE = BigInteger.ONE; // 1 wei final Credentials notDenied = Credentials.create(Accounts.GENESIS_ACCOUNT_ONE_PRIVATE_KEY); - final Credentials willbeDenied = Credentials.create(Accounts.GENESIS_ACCOUNT_TWO_PRIVATE_KEY); + final Credentials willBeDenied = Credentials.create(Accounts.GENESIS_ACCOUNT_TWO_PRIVATE_KEY); @TempDir static Path tempDir; static Path tempDenyList; @@ -49,6 +49,14 @@ public class TransactionPoolDenyListReloadTest extends LineaPluginTestBase { @Override public List getTestCliOptions() { tempDenyList = tempDir.resolve("denyList.txt"); + if (!Files.exists(tempDenyList)) { + + try { + Files.createFile(tempDenyList); + } catch (IOException e) { + throw new RuntimeException(e); + } + } return new TestCommandLineOptionsBuilder() .set("--plugin-linea-deny-list-path=", tempDenyList.toString()) .build(); @@ -59,22 +67,22 @@ public void emptyDenyList() throws Exception { final Web3j miner = minerNode.nodeRequests().eth(); RawTransactionManager transactionManager = - new RawTransactionManager(miner, willbeDenied, CHAIN_ID); - assertAddressAllowed(transactionManager, willbeDenied.getAddress()); + new RawTransactionManager(miner, willBeDenied, CHAIN_ID); + assertAddressAllowed(transactionManager, willBeDenied.getAddress()); } @Test public void emptyDenyList_thenDenySender_cannotAddTxToPool() throws Exception { final Web3j miner = minerNode.nodeRequests().eth(); RawTransactionManager transactionManager = - new RawTransactionManager(miner, willbeDenied, CHAIN_ID); + new RawTransactionManager(miner, willBeDenied, CHAIN_ID); - assertAddressAllowed(transactionManager, willbeDenied.getAddress()); + assertAddressAllowed(transactionManager, willBeDenied.getAddress()); - addAddressToDenyList(willbeDenied.getAddress()); + addAddressToDenyList(willBeDenied.getAddress()); reloadPluginConfig(); - assertAddressNotAllowed(transactionManager, willbeDenied.getAddress()); + assertAddressNotAllowed(transactionManager, willBeDenied.getAddress()); } private void addAddressToDenyList(final String address) throws IOException { @@ -97,30 +105,27 @@ private void assertAddressNotAllowed( assertThat(transactionResponse.getTransactionHash()).isNull(); assertThat(transactionResponse.getError().getMessage()) .isEqualTo( - "recipient " + "sender " + address + " is blocked as appearing on the SDN or other legally prohibited list"); } private void reloadPluginConfig() { - System.out.println("GOT HERE ******"); final var reqLinea = new ReloadPluginConfigRequest(); - System.out.println("88888888" + reqLinea); final var respLinea = reqLinea.execute(minerNode.nodeRequests()); - System.out.println("88888888" + respLinea); - assertThat(respLinea.booleanValue()).isTrue(); + assertThat(respLinea).isEqualTo("Success"); } - static class ReloadPluginConfigRequest implements Transaction { + static class ReloadPluginConfigRequest implements Transaction { public ReloadPluginConfigRequest() {} @Override - public Boolean execute(final NodeRequests nodeRequests) { + public String execute(final NodeRequests nodeRequests) { try { return new Request<>( "plugins_reloadPluginConfig", - List.of(), + List.of("LineaTransactionPoolValidatorPlugin"), nodeRequests.getWeb3jService(), ReloadPluginConfigResponse.class) .send() @@ -131,5 +136,5 @@ public Boolean execute(final NodeRequests nodeRequests) { } } - static class ReloadPluginConfigResponse extends org.web3j.protocol.core.Response {} + static class ReloadPluginConfigResponse extends org.web3j.protocol.core.Response {} } From 5d2142777b78f41fdada62081661f62852859846 Mon Sep 17 00:00:00 2001 From: Sally MacFarlane Date: Mon, 14 Oct 2024 15:17:25 +1000 Subject: [PATCH 7/9] enable plugins api group Signed-off-by: Sally MacFarlane --- .../test/java/linea/plugin/acc/test/LineaPluginTestBase.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/acceptance-tests/src/test/java/linea/plugin/acc/test/LineaPluginTestBase.java b/acceptance-tests/src/test/java/linea/plugin/acc/test/LineaPluginTestBase.java index c5d08d7a..9b74a2c8 100644 --- a/acceptance-tests/src/test/java/linea/plugin/acc/test/LineaPluginTestBase.java +++ b/acceptance-tests/src/test/java/linea/plugin/acc/test/LineaPluginTestBase.java @@ -79,7 +79,10 @@ public class LineaPluginTestBase extends AcceptanceTestBase { public void setup() throws Exception { minerNode = createCliqueNodeWithExtraCliOptionsAndRpcApis( - "miner1", LINEA_CLIQUE_OPTIONS, getTestCliOptions(), Set.of("LINEA", "MINER")); + "miner1", + LINEA_CLIQUE_OPTIONS, + getTestCliOptions(), + Set.of("LINEA", "MINER", "PLUGINS")); minerNode.setTransactionPoolConfiguration( ImmutableTransactionPoolConfiguration.builder() .from(TransactionPoolConfiguration.DEFAULT) From 8f774544572dac7b2b5f5e0213458c2be1115576 Mon Sep 17 00:00:00 2001 From: Sally MacFarlane Date: Mon, 14 Oct 2024 15:17:32 +1000 Subject: [PATCH 8/9] plugin name Signed-off-by: Sally MacFarlane --- .../plugin/acc/test/TransactionPoolDenyListReloadTest.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/acceptance-tests/src/test/java/linea/plugin/acc/test/TransactionPoolDenyListReloadTest.java b/acceptance-tests/src/test/java/linea/plugin/acc/test/TransactionPoolDenyListReloadTest.java index 8e0e68cf..f573e734 100644 --- a/acceptance-tests/src/test/java/linea/plugin/acc/test/TransactionPoolDenyListReloadTest.java +++ b/acceptance-tests/src/test/java/linea/plugin/acc/test/TransactionPoolDenyListReloadTest.java @@ -123,9 +123,11 @@ public ReloadPluginConfigRequest() {} @Override public String execute(final NodeRequests nodeRequests) { try { + // plugin name is class name return new Request<>( "plugins_reloadPluginConfig", - List.of("LineaTransactionPoolValidatorPlugin"), + List.of( + "net.consensys.linea.sequencer.txpoolvalidation.LineaTransactionPoolValidatorPlugin"), nodeRequests.getWeb3jService(), ReloadPluginConfigResponse.class) .send() From 20389b8e787707b3227021279b43a21f319c06c2 Mon Sep 17 00:00:00 2001 From: Sally MacFarlane Date: Mon, 14 Oct 2024 15:09:30 +1000 Subject: [PATCH 9/9] cherry-pick 0fe75ca5 for plugin name change Signed-off-by: Sally MacFarlane --- .../linea/AbstractLineaRequiredPlugin.java | 32 ++++++++++++++++++- .../linea/extradata/LineaExtraDataPlugin.java | 8 ----- .../LineaTransactionPoolValidatorPlugin.java | 6 ---- .../LineaTransactionSelectorPlugin.java | 6 ---- 4 files changed, 31 insertions(+), 21 deletions(-) diff --git a/sequencer/src/main/java/net/consensys/linea/AbstractLineaRequiredPlugin.java b/sequencer/src/main/java/net/consensys/linea/AbstractLineaRequiredPlugin.java index c3b51351..26423735 100644 --- a/sequencer/src/main/java/net/consensys/linea/AbstractLineaRequiredPlugin.java +++ b/sequencer/src/main/java/net/consensys/linea/AbstractLineaRequiredPlugin.java @@ -18,9 +18,11 @@ import lombok.extern.slf4j.Slf4j; import org.hyperledger.besu.plugin.BesuContext; import org.hyperledger.besu.plugin.BesuPlugin; +import org.hyperledger.besu.plugin.services.BlockchainService; @Slf4j public abstract class AbstractLineaRequiredPlugin extends AbstractLineaPrivateOptionsPlugin { + protected BlockchainService blockchainService; /** * Linea plugins extending this class will halt startup of Besu in case of exception during @@ -34,7 +36,18 @@ public abstract class AbstractLineaRequiredPlugin extends AbstractLineaPrivateOp public void register(final BesuContext context) { super.register(context); try { - log.info("Registering Linea plugin " + this.getClass().getName()); + log.info( + "Registering Linea plugin of type {} with name {}", + this.getClass().getName(), + this.getName()); + + blockchainService = + context + .getService(BlockchainService.class) + .orElseThrow( + () -> + new RuntimeException( + "Failed to obtain BlockchainService from the BesuContext.")); doRegister(context); @@ -52,4 +65,21 @@ public void register(final BesuContext context) { * @param context */ public abstract void doRegister(final BesuContext context); + + @Override + public void start() { + super.start(); + + blockchainService + .getChainId() + .ifPresentOrElse( + chainId -> { + if (chainId.signum() <= 0) { + throw new IllegalArgumentException("Chain id must be greater than zero."); + } + }, + () -> { + throw new IllegalArgumentException("Chain id required"); + }); + } } diff --git a/sequencer/src/main/java/net/consensys/linea/extradata/LineaExtraDataPlugin.java b/sequencer/src/main/java/net/consensys/linea/extradata/LineaExtraDataPlugin.java index 7fe0aa98..8ff08aa4 100644 --- a/sequencer/src/main/java/net/consensys/linea/extradata/LineaExtraDataPlugin.java +++ b/sequencer/src/main/java/net/consensys/linea/extradata/LineaExtraDataPlugin.java @@ -15,8 +15,6 @@ package net.consensys.linea.extradata; -import java.util.Optional; - import com.google.auto.service.AutoService; import lombok.extern.slf4j.Slf4j; import net.consensys.linea.AbstractLineaRequiredPlugin; @@ -30,16 +28,10 @@ @Slf4j @AutoService(BesuPlugin.class) public class LineaExtraDataPlugin extends AbstractLineaRequiredPlugin { - public static final String NAME = "linea"; private BesuContext besuContext; private RpcEndpointService rpcEndpointService; private BlockchainService blockchainService; - @Override - public Optional getName() { - return Optional.of(NAME); - } - @Override public void doRegister(final BesuContext context) { besuContext = context; diff --git a/sequencer/src/main/java/net/consensys/linea/sequencer/txpoolvalidation/LineaTransactionPoolValidatorPlugin.java b/sequencer/src/main/java/net/consensys/linea/sequencer/txpoolvalidation/LineaTransactionPoolValidatorPlugin.java index 3c73b389..c196e719 100644 --- a/sequencer/src/main/java/net/consensys/linea/sequencer/txpoolvalidation/LineaTransactionPoolValidatorPlugin.java +++ b/sequencer/src/main/java/net/consensys/linea/sequencer/txpoolvalidation/LineaTransactionPoolValidatorPlugin.java @@ -46,17 +46,11 @@ @Slf4j @AutoService(BesuPlugin.class) public class LineaTransactionPoolValidatorPlugin extends AbstractLineaRequiredPlugin { - public static final String NAME = "linea"; private BesuConfiguration besuConfiguration; private BlockchainService blockchainService; private TransactionPoolValidatorService transactionPoolValidatorService; private TransactionSimulationService transactionSimulationService; - @Override - public Optional getName() { - return Optional.of(NAME); - } - @Override public void doRegister(final BesuContext context) { besuConfiguration = diff --git a/sequencer/src/main/java/net/consensys/linea/sequencer/txselection/LineaTransactionSelectorPlugin.java b/sequencer/src/main/java/net/consensys/linea/sequencer/txselection/LineaTransactionSelectorPlugin.java index 1ca96d48..e6bdb549 100644 --- a/sequencer/src/main/java/net/consensys/linea/sequencer/txselection/LineaTransactionSelectorPlugin.java +++ b/sequencer/src/main/java/net/consensys/linea/sequencer/txselection/LineaTransactionSelectorPlugin.java @@ -38,17 +38,11 @@ @Slf4j @AutoService(BesuPlugin.class) public class LineaTransactionSelectorPlugin extends AbstractLineaRequiredPlugin { - public static final String NAME = "linea"; private TransactionSelectionService transactionSelectionService; private BlockchainService blockchainService; private Optional rejectedTxJsonRpcManager = Optional.empty(); private BesuConfiguration besuConfiguration; - @Override - public Optional getName() { - return Optional.of(NAME); - } - @Override public void doRegister(final BesuContext context) { transactionSelectionService =