Skip to content

Commit

Permalink
Merge pull request #101 from web3j/besuUpdate
Browse files Browse the repository at this point in the history
Besu upgrade
  • Loading branch information
gtebrean authored Feb 15, 2024
2 parents c8b9934 + 64741c0 commit 677cfc5
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 16 deletions.
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ plugins {
description 'Web3j-evm extension'

ext {
web3jVersion = '4.10.3'
web3jVersion = '4.11.0'
log4jVersion = '2.15.0'
guavaVersion = '28.1-jre'
jacksonVersion = '2.10.0'
klaxonVersion = '5.0.1'
kotlinVersion = '1.8.10'
besuPluginVersion = '23.7.0'
besuInternalVersion = '23.7.0'
besuPluginVersion = '24.1.1'
besuInternalVersion = '24.1.1'
besuInternalCryptoVersion = '23.1.3'
besuCryptoDepVersion = '0.7.1'
besuCryptoDepVersion = '0.8.3'
}

apply {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
kotlin.code.style=official
group=org.web3j
version=4.10.4-SNAPSHOT
version=4.11.0-SNAPSHOT
36 changes: 33 additions & 3 deletions src/main/kotlin/org/web3j/evm/EmbeddedEthereum.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,23 @@ import java.util.Optional
import org.web3j.abi.datatypes.Address as wAddress
import org.web3j.protocol.core.methods.request.Transaction as wTransaction
import org.web3j.protocol.core.methods.response.TransactionReceipt as wTransactionReceipt
import com.google.common.io.Resources
import java.nio.charset.StandardCharsets
import org.hyperledger.besu.cli.config.EthNetworkConfig
import org.hyperledger.besu.cli.config.NetworkName
import org.hyperledger.besu.config.GenesisConfigFile
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.WithdrawalParameter
import org.hyperledger.besu.ethereum.core.PrivacyParameters
import org.hyperledger.besu.ethereum.mainnet.MainnetProtocolSchedule
import org.hyperledger.besu.evm.internal.EvmConfiguration
import org.web3j.evm.utils.TestAccountsConstants
import org.web3j.protocol.core.methods.response.EthBlock.Withdrawal

/**
* Embedded Web3j Ethereum blockchain.
*/
class EmbeddedEthereum(
configuration: Configuration,
private val configuration: Configuration,
operationTracer: OperationTracer
) {
private val chain = InMemoryBesuChain(configuration, operationTracer)
Expand Down Expand Up @@ -123,8 +131,29 @@ class EmbeddedEthereum(
fun getTransactionReceipt(transactionHashParam: String): wTransactionReceipt? {
val hash = Hash.fromHexStringLenient(transactionHashParam)

val genesisConfig = if (configuration.genesisFileUrl === null) {
val networkConfig = EthNetworkConfig.getNetworkConfig(NetworkName.DEV)
GenesisConfigFile.fromConfig(networkConfig.genesisConfig)
} else {
GenesisConfigFile.fromConfig(
@Suppress("UnstableApiUsage")
Resources.toString(
configuration.genesisFileUrl,
StandardCharsets.UTF_8
)
)
}
val configOptions = genesisConfig.getConfigOptions(InMemoryBesuChain.DEFAULT_GENESIS_OVERRIDES)

val protocolSchedule = MainnetProtocolSchedule.fromConfig(
configOptions,
PrivacyParameters.DEFAULT,
true,
EvmConfiguration.DEFAULT
)

val result = blockchainQueries
.transactionReceiptByTransactionHash(hash)
.transactionReceiptByTransactionHash(hash, protocolSchedule)
.map { receipt -> getResult(receipt) }
.orElse(null)
?: return null
Expand Down Expand Up @@ -260,12 +289,13 @@ class EmbeddedEthereum(
tcr.r,
tcr.s,
hexToULong(tcr.v),
tcr.yParity,
tcr.type,
tcr.maxFeePerGas,
tcr.maxPriorityFeePerGas,
tcr.accessList?.map {
AccessListObject(
it.address.toHexString(),
it.address.toString(),
mutableListOf(it.storageKeys.toString())
)
}
Expand Down
18 changes: 10 additions & 8 deletions src/main/kotlin/org/web3j/evm/InMemoryBesuChain.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ import org.hyperledger.besu.ethereum.mainnet.MainnetProtocolSchedule
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule
import org.hyperledger.besu.ethereum.mainnet.ScheduleBasedBlockHeaderFunctions
import org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueStoragePrefixedKeyBlockchainStorage
import org.hyperledger.besu.ethereum.storage.keyvalue.WorldStateKeyValueStorage
import org.hyperledger.besu.ethereum.trie.forest.storage.ForestWorldStateKeyValueStorage
import org.hyperledger.besu.ethereum.storage.keyvalue.WorldStatePreimageKeyValueStorage
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.evm.tracing.OperationTracer
import org.hyperledger.besu.ethereum.worldstate.DefaultWorldStateArchive
import org.hyperledger.besu.ethereum.trie.forest.ForestWorldStateArchive
import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive
import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem
import org.hyperledger.besu.services.kvstore.InMemoryKeyValueStorage
Expand Down Expand Up @@ -110,12 +110,13 @@ class InMemoryBesuChain(
val blockchainStorage = KeyValueStoragePrefixedKeyBlockchainStorage(
keyValueStorage, variablesStorage, MainnetBlockHeaderFunctions()
)
val worldStateStorage = WorldStateKeyValueStorage(InMemoryKeyValueStorage())
val worldStateStorage = ForestWorldStateKeyValueStorage(InMemoryKeyValueStorage())
val worldStatePreimageStorage = WorldStatePreimageKeyValueStorage(InMemoryKeyValueStorage())

worldStateArchive = DefaultWorldStateArchive(
worldStateArchive = ForestWorldStateArchive(
worldStateStorage,
worldStatePreimageStorage
worldStatePreimageStorage,
EvmConfiguration.DEFAULT
)
worldState = worldStateArchive.mutable
worldStateUpdater = worldState.updater()
Expand Down Expand Up @@ -150,7 +151,8 @@ class InMemoryBesuChain(
simulator = TransactionSimulator(
blockChain,
worldStateArchive,
protocolSchedule
protocolSchedule,
0L
)
}

Expand Down Expand Up @@ -283,14 +285,14 @@ class InMemoryBesuChain(
val spec = protocolSchedule.getByBlockHeader(blockChain.chainHeadHeader)
val coinbaseReward: Wei = spec.blockReward
val updater = worldState.updater()
val coinbase = updater.getOrCreate(coinbaseAddress).mutable
val coinbase = updater.getOrCreate(coinbaseAddress)
coinbase.incrementBalance(coinbaseReward)
updater.commit()
}

companion object {
private val LOG = LoggerFactory.getLogger(InMemoryBesuChain::class.java)
private val DEFAULT_GENESIS_OVERRIDES = mapOf(
internal val DEFAULT_GENESIS_OVERRIDES = mapOf(
"londonblock" to "1",
"petersburgblock" to "0"
)
Expand Down

0 comments on commit 677cfc5

Please sign in to comment.