diff --git a/coordinator/core/build.gradle b/coordinator/core/build.gradle index 1fcaa5a7e..8b2b8cc6d 100644 --- a/coordinator/core/build.gradle +++ b/coordinator/core/build.gradle @@ -18,7 +18,7 @@ dependencies { implementation project(":jvm-libs:teku-execution-client") implementation "io.vertx:vertx-core" // jackson shall never be used in the core module - // however, it is used already :( but was as transitive throught Teku Execution Client + // however, it is used already :( but was as transitive through Teku Execution Client // necessary atm because of Type2StateManagerClient interface implementation "com.fasterxml.jackson.core:jackson-databind:${libs.versions.jackson.get()}" // jackson shall never be used in the core module diff --git a/coordinator/ethereum/message-anchoring/src/integrationTest/kotlin/net.consensys.zkevm.ethereum.coordination.messageanchoring/L1EventQuerierIntegrationTest.kt b/coordinator/ethereum/message-anchoring/src/integrationTest/kotlin/net.consensys.zkevm.ethereum.coordination.messageanchoring/L1EventQuerierIntegrationTest.kt index 3a2bcb139..2898d4df2 100644 --- a/coordinator/ethereum/message-anchoring/src/integrationTest/kotlin/net.consensys.zkevm.ethereum.coordination.messageanchoring/L1EventQuerierIntegrationTest.kt +++ b/coordinator/ethereum/message-anchoring/src/integrationTest/kotlin/net.consensys.zkevm.ethereum.coordination.messageanchoring/L1EventQuerierIntegrationTest.kt @@ -9,7 +9,7 @@ import net.consensys.linea.contract.LineaRollupAsyncFriendly import net.consensys.toBigInteger import net.consensys.toULong import net.consensys.zkevm.ethereum.ContractsManager -import net.consensys.zkevm.ethereum.L1AccountManager +import net.consensys.zkevm.ethereum.Web3jClientManager import org.apache.tuweni.bytes.Bytes32 import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.BeforeEach @@ -37,7 +37,7 @@ class L1EventQuerierIntegrationTest { fun beforeEach() { val deploymentResult = ContractsManager.get().deployLineaRollup().get() testLineaRollupContractAddress = deploymentResult.contractAddress - web3Client = L1AccountManager.web3jClient + web3Client = Web3jClientManager.l1Client @Suppress("DEPRECATION") contract = deploymentResult.rollupOperatorClientLegacy l1ContractDeploymentBlockNumber = deploymentResult.contractDeploymentBlockNumber.toULong() diff --git a/coordinator/ethereum/message-anchoring/src/integrationTest/kotlin/net.consensys.zkevm.ethereum.coordination.messageanchoring/L2MessageAnchorerIntegrationTest.kt b/coordinator/ethereum/message-anchoring/src/integrationTest/kotlin/net.consensys.zkevm.ethereum.coordination.messageanchoring/L2MessageAnchorerIntegrationTest.kt index 4c49913f6..e5a03a44b 100644 --- a/coordinator/ethereum/message-anchoring/src/integrationTest/kotlin/net.consensys.zkevm.ethereum.coordination.messageanchoring/L2MessageAnchorerIntegrationTest.kt +++ b/coordinator/ethereum/message-anchoring/src/integrationTest/kotlin/net.consensys.zkevm.ethereum.coordination.messageanchoring/L2MessageAnchorerIntegrationTest.kt @@ -13,8 +13,7 @@ import net.consensys.linea.contract.LineaRollupAsyncFriendly import net.consensys.toBigInteger import net.consensys.zkevm.coordinator.clients.smartcontract.LineaRollupSmartContractClient import net.consensys.zkevm.ethereum.ContractsManager -import net.consensys.zkevm.ethereum.L1AccountManager -import net.consensys.zkevm.ethereum.L2AccountManager +import net.consensys.zkevm.ethereum.Web3jClientManager import org.apache.tuweni.bytes.Bytes32 import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.BeforeEach @@ -61,8 +60,8 @@ class L2MessageAnchorerIntegrationTest { val deploymentResult = ContractsManager.get().deployRollupAndL2MessageService().get() testLineaRollupContractAddress = deploymentResult.lineaRollup.contractAddress l1ContractDeploymentBlockNumber = deploymentResult.lineaRollup.contractDeploymentBlockNumber - l1Web3jClient = L1AccountManager.web3jClient - l2Web3jClient = L2AccountManager.web3jClient + l1Web3jClient = Web3jClientManager.l1Client + l2Web3jClient = Web3jClientManager.l2Client l2TransactionManager = deploymentResult.l2MessageService.anchorerOperator.txManager @Suppress("DEPRECATION") l1ContractLegacyClient = deploymentResult.lineaRollup.rollupOperatorClientLegacy diff --git a/coordinator/ethereum/message-anchoring/src/integrationTest/kotlin/net.consensys.zkevm.ethereum.coordination.messageanchoring/MessageServiceIntegrationTest.kt b/coordinator/ethereum/message-anchoring/src/integrationTest/kotlin/net.consensys.zkevm.ethereum.coordination.messageanchoring/MessageServiceIntegrationTest.kt index 2959b8952..e99a2e9a3 100644 --- a/coordinator/ethereum/message-anchoring/src/integrationTest/kotlin/net.consensys.zkevm.ethereum.coordination.messageanchoring/MessageServiceIntegrationTest.kt +++ b/coordinator/ethereum/message-anchoring/src/integrationTest/kotlin/net.consensys.zkevm.ethereum.coordination.messageanchoring/MessageServiceIntegrationTest.kt @@ -12,8 +12,7 @@ import net.consensys.toBigInteger import net.consensys.toULong import net.consensys.zkevm.coordinator.clients.smartcontract.LineaRollupSmartContractClient import net.consensys.zkevm.ethereum.ContractsManager -import net.consensys.zkevm.ethereum.L1AccountManager -import net.consensys.zkevm.ethereum.L2AccountManager +import net.consensys.zkevm.ethereum.Web3jClientManager import org.apache.logging.log4j.LogManager import org.apache.logging.log4j.Logger import org.assertj.core.api.Assertions.assertThat @@ -33,8 +32,8 @@ class MessageServiceIntegrationTest { private val log: Logger = LogManager.getLogger(this::class.java) private val l2RecipientAddress = "0x03dfa322A95039BB679771346Ee2dBfEa0e2B773" - private val l1Web3Client = L1AccountManager.web3jClient - private val l2Web3jClient = L2AccountManager.web3jClient + private val l1Web3Client = Web3jClientManager.l1Client + private val l2Web3jClient = Web3jClientManager.l2Client private lateinit var l2TransactionManager: AsyncFriendlyTransactionManager private val messagePollingInterval = 200.milliseconds diff --git a/coordinator/ethereum/test-utils/src/main/kotlin/net/consensys/zkevm/ethereum/AccountManager.kt b/coordinator/ethereum/test-utils/src/main/kotlin/net/consensys/zkevm/ethereum/AccountManager.kt index 2733d8596..f8d0c1105 100644 --- a/coordinator/ethereum/test-utils/src/main/kotlin/net/consensys/zkevm/ethereum/AccountManager.kt +++ b/coordinator/ethereum/test-utils/src/main/kotlin/net/consensys/zkevm/ethereum/AccountManager.kt @@ -12,9 +12,7 @@ import org.web3j.crypto.Credentials import org.web3j.protocol.Web3j import org.web3j.protocol.core.DefaultBlockParameterName import org.web3j.protocol.core.Response -import org.web3j.protocol.http.HttpService import org.web3j.tx.response.PollingTransactionReceiptProcessor -import org.web3j.utils.Async import tech.pegasys.teku.infrastructure.async.SafeFuture import java.io.File import java.math.BigInteger @@ -75,7 +73,6 @@ fun getTransactionManager( private inline val Int.ether get(): BigInteger = BigInteger.valueOf(this.toLong()).multiply(BigInteger.TEN.pow(18)) interface AccountManager { - val web3jClient: Web3j val chainId: Long fun whaleAccount(): Account fun generateAccount(initialBalanceWei: BigInteger = 10.ether): Account @@ -85,13 +82,12 @@ interface AccountManager { } private open class WhaleBasedAccountManager( - rpcUrl: String, + val web3jClient: Web3j, genesisFile: Path, val clock: Clock = Clock.System, val testWorkerIdProvider: () -> Long = { ProcessHandle.current().pid() }, val log: Logger = LogManager.getLogger(WhaleBasedAccountManager::class.java) ) : AccountManager { - override val web3jClient: Web3j = Web3j.build(HttpService(rpcUrl), 500, Async.defaultExecutorService()) private val whaleAccounts: List final override val chainId: Long @@ -224,13 +220,13 @@ private open class WhaleBasedAccountManager( } object L1AccountManager : AccountManager by WhaleBasedAccountManager( - rpcUrl = System.getProperty("L1_RPC", "http://localhost:8445"), + web3jClient = Web3jClientManager.l1Client, genesisFile = findFile(System.getProperty("L1_GENESIS", "docker/config/l1-node/el/genesis.json")), log = LogManager.getLogger(L1AccountManager::class.java) ) object L2AccountManager : AccountManager by WhaleBasedAccountManager( - rpcUrl = System.getProperty("L2_RPC", "http://localhost:8545"), + web3jClient = Web3jClientManager.l2Client, genesisFile = findFile(System.getProperty("L2_GENESIS", "docker/config/linea-local-dev-genesis.json")), log = LogManager.getLogger(L2AccountManager::class.java) ) diff --git a/coordinator/ethereum/test-utils/src/main/kotlin/net/consensys/zkevm/ethereum/ContractsManager.kt b/coordinator/ethereum/test-utils/src/main/kotlin/net/consensys/zkevm/ethereum/ContractsManager.kt index e5f48764c..171aa9ff7 100644 --- a/coordinator/ethereum/test-utils/src/main/kotlin/net/consensys/zkevm/ethereum/ContractsManager.kt +++ b/coordinator/ethereum/test-utils/src/main/kotlin/net/consensys/zkevm/ethereum/ContractsManager.kt @@ -80,7 +80,7 @@ interface ContractsManager { fun connectL2MessageService( contractAddress: String, - web3jClient: Web3j = L2AccountManager.web3jClient, + web3jClient: Web3j = Web3jClientManager.l2Client, transactionManager: AsyncFriendlyTransactionManager, gasProvider: EIP1559GasProvider = EIP1559GasProvider( web3jClient, @@ -193,7 +193,7 @@ object MakeFileDelegatedContractsManager : ContractsManager { ): LineaRollupAsyncFriendly { return LineaRollupAsyncFriendly.load( contractAddress, - L1AccountManager.web3jClient, + Web3jClientManager.l1Client, transactionManager, gasProvider, emptyMap() @@ -207,7 +207,7 @@ object MakeFileDelegatedContractsManager : ContractsManager { ): LineaRollupSmartContractClient { return Web3JLineaRollupSmartContractClient.load( contractAddress, - L1AccountManager.web3jClient, + Web3jClientManager.l1Client, transactionManager, gasProvider, emptyMap() diff --git a/coordinator/ethereum/test-utils/src/main/kotlin/net/consensys/zkevm/ethereum/Web3jClientManager.kt b/coordinator/ethereum/test-utils/src/main/kotlin/net/consensys/zkevm/ethereum/Web3jClientManager.kt new file mode 100644 index 000000000..dddcd0cec --- /dev/null +++ b/coordinator/ethereum/test-utils/src/main/kotlin/net/consensys/zkevm/ethereum/Web3jClientManager.kt @@ -0,0 +1,58 @@ +package net.consensys.zkevm.ethereum + +import net.consensys.linea.web3j.okHttpClientBuilder +import org.apache.logging.log4j.Level +import org.apache.logging.log4j.LogManager +import org.apache.logging.log4j.Logger +import org.web3j.protocol.Web3j +import org.web3j.protocol.http.HttpService +import org.web3j.utils.Async + +/** + * Helper Object to create Web3j clients for L1 and L2 + * that allow overriding default log values for testing and debugging easily + */ +object Web3jClientManager { + val l1RpcUrl: String = System.getProperty("L1_RPC", "http://localhost:8445") + val l2RpcUrl: String = System.getProperty("L2_RPC", "http://localhost:8545") + val l1Client: Web3j = buildL1Client() + val l2Client: Web3j = buildL2Client() + + fun buildL1Client( + rpcUrl: String = l1RpcUrl, + log: Logger = LogManager.getLogger("test.clients.l1.web3j-default"), + requestResponseLogLevel: Level = Level.TRACE, + failuresLogLevel: Level = Level.DEBUG + ): Web3j { + return buildWeb3Client(rpcUrl, log, requestResponseLogLevel, failuresLogLevel) + } + + fun buildL2Client( + rpcUrl: String = l2RpcUrl, + log: Logger = LogManager.getLogger("test.clients.l2.web3j-default"), + requestResponseLogLevel: Level = Level.TRACE, + failuresLogLevel: Level = Level.DEBUG + ): Web3j { + return buildWeb3Client(rpcUrl, log, requestResponseLogLevel, failuresLogLevel) + } + + fun buildWeb3Client( + rpcUrl: String, + log: Logger = LogManager.getLogger("test.clients.web3j"), + requestResponseLogLevel: Level = Level.TRACE, + failuresLogLevel: Level = Level.DEBUG + ): Web3j { + return Web3j.build( + HttpService( + rpcUrl, + okHttpClientBuilder( + logger = log, + requestResponseLogLevel = requestResponseLogLevel, + failuresLogLevel = failuresLogLevel + ).build() + ), + 500, + Async.defaultExecutorService() + ) + } +} diff --git a/jvm-libs/web3j-extensions/src/main/kotlin/net/consensys/linea/web3j/OkHttpClientLogging.kt b/jvm-libs/web3j-extensions/src/main/kotlin/net/consensys/linea/web3j/OkHttpClientLogging.kt index feb43d410..9de674016 100644 --- a/jvm-libs/web3j-extensions/src/main/kotlin/net/consensys/linea/web3j/OkHttpClientLogging.kt +++ b/jvm-libs/web3j-extensions/src/main/kotlin/net/consensys/linea/web3j/OkHttpClientLogging.kt @@ -7,6 +7,7 @@ import okhttp3.Interceptor import okhttp3.OkHttpClient import okhttp3.Response import okio.Buffer +import org.apache.logging.log4j.Level import org.apache.logging.log4j.LogManager import org.apache.logging.log4j.Logger import org.web3j.protocol.http.HttpService @@ -52,17 +53,19 @@ class OkHttpMinimalJsonRpcLoggerInterceptor( } fun okHttpClientBuilder( - logger: Logger = LogManager.getLogger(HttpService::class.java) // use same class to keep backward compatibility + logger: Logger = LogManager.getLogger(HttpService::class.java), // use same class to keep backward compatibility + // we make a lot of eth_call request that fail by design, having DEBUG/WARN level is too noisy + // ideally we should manage methods individually, but don't have time for that now + requestResponseLogLevel: Level = Level.TRACE, + failuresLogLevel: Level = Level.DEBUG ): OkHttpClient.Builder { val httpClientBuilder = OkHttpClient.Builder() httpClientBuilder.addInterceptor( OkHttpMinimalJsonRpcLoggerInterceptor( MinimalInLineJsonRpcLogger( logger, - // we make a lot of eth_call request that fail by design, having DEBUG/WARN level is too noisy - // ideally we should manage methods individually, but don't have time for that now - requestResponseLogLevel = org.apache.logging.log4j.Level.TRACE, - failuresLogLevel = org.apache.logging.log4j.Level.DEBUG, + requestResponseLogLevel = requestResponseLogLevel, + failuresLogLevel = failuresLogLevel, maskEndpoint = ::maskEndpointPath ) )