Skip to content

Commit

Permalink
Upgrade to Apache Tuweni 2.0 (hyperledger#2376)
Browse files Browse the repository at this point in the history
* Upgrade to Apache Tuweni 2.0

Signed-off-by: Antoine Toulme <antoine@lunar-ocean.com>

* Remove intermediate repository

Signed-off-by: Antoine Toulme <antoine@lunar-ocean.com>

* Remove all occurrences of toBytes

Signed-off-by: Antoine Toulme <antoine@lunar-ocean.com>

* Migrate to tuweni-bytes

Signed-off-by: Antoine Toulme <antoine@lunar-ocean.com>

* add changelog

Signed-off-by: Antoine Toulme <antoine@lunar-ocean.com>

* correct reference tests

Signed-off-by: Antoine Toulme <antoine@lunar-ocean.com>

* Initial API changes

Signed-off-by: Antoine Toulme <antoine@lunar-ocean.com>

* more changes

Signed-off-by: Antoine Toulme <antoine@lunar-ocean.com>

* Change APIs for VM ops

Signed-off-by: Antoine Toulme <antoine@lunar-ocean.com>

* Use constant UInt256.ONE

Signed-off-by: Antoine Toulme <antoine@lunar-ocean.com>

* Optimize a bit address <> word transformation

Signed-off-by: Antoine Toulme <antoine@lunar-ocean.com>

* spotless

Signed-off-by: Antoine Toulme <antoine@lunar-ocean.com>
  • Loading branch information
atoulme authored Jul 16, 2021
1 parent ff67cc6 commit 11f5cfb
Show file tree
Hide file tree
Showing 164 changed files with 414 additions and 428 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## 21.7.2
### Additions and Improvements
- Migration to Apache Tuweni 2.0 [\#2376](https://github.com/hyperledger/besu/pull/2376)

### Bug Fixes

Expand Down
6 changes: 3 additions & 3 deletions acceptance-tests/dsl/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ dependencies {
implementation 'org.apache.logging.log4j:log4j-api'
implementation 'org.apache.logging.log4j:log4j-core'
implementation 'org.apache.logging.log4j:log4j-slf4j-impl'
implementation 'org.apache.tuweni:bytes'
implementation 'org.apache.tuweni:io'
implementation 'org.apache.tuweni:units'
implementation 'org.apache.tuweni:tuweni-bytes'
implementation 'org.apache.tuweni:tuweni-io'
implementation 'org.apache.tuweni:tuweni-units'
implementation 'org.assertj:assertj-core'
implementation 'org.awaitility:awaitility'
implementation 'org.java-websocket:Java-WebSocket'
Expand Down
2 changes: 1 addition & 1 deletion acceptance-tests/tests/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ dependencies {
testImplementation 'junit:junit'
testImplementation 'net.consensys:orion'
testImplementation 'org.apache.commons:commons-compress'
testImplementation 'org.apache.tuweni:crypto'
testImplementation 'org.apache.tuweni:tuweni-crypto'
testImplementation 'org.assertj:assertj-core'
testImplementation 'org.awaitility:awaitility'
testImplementation 'org.web3j:abi'
Expand Down
12 changes: 6 additions & 6 deletions besu/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ dependencies {
implementation 'io.vertx:vertx-web'
implementation 'org.apache.logging.log4j:log4j-api'
implementation 'org.apache.logging.log4j:log4j-core'
implementation 'org.apache.tuweni:bytes'
implementation 'org.apache.tuweni:config'
implementation 'org.apache.tuweni:toml'
implementation 'org.apache.tuweni:units'
implementation 'org.apache.tuweni:tuweni-bytes'
implementation 'org.apache.tuweni:tuweni-config'
implementation 'org.apache.tuweni:tuweni-toml'
implementation 'org.apache.tuweni:tuweni-units'
implementation 'org.springframework.security:spring-security-crypto'
implementation 'org.xerial.snappy:snappy-java'
implementation 'net.consensys.services:quorum-mainnet-launcher'
Expand All @@ -85,8 +85,8 @@ dependencies {
testImplementation 'com.squareup.okhttp3:okhttp'
testImplementation 'junit:junit'
testImplementation 'org.apache.commons:commons-text'
testImplementation 'org.apache.tuweni:bytes'
testImplementation 'org.apache.tuweni:units'
testImplementation 'org.apache.tuweni:tuweni-bytes'
testImplementation 'org.apache.tuweni:tuweni-units'
testImplementation 'org.assertj:assertj-core'
testImplementation 'org.awaitility:awaitility'
testImplementation 'org.mockito:mockito-core'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3660,7 +3660,7 @@ public void invalidTansactionPoolPriceBumpShouldFail() {
@Test
public void transactionPoolTxFeeCap() {
final Wei txFeeCap = Wei.fromEth(2);
parseCommand("--rpc-tx-feecap", txFeeCap.toString());
parseCommand("--rpc-tx-feecap", txFeeCap.toDecimalString());
verify(mockControllerBuilder)
.transactionPoolConfiguration(transactionPoolConfigCaptor.capture());
assertThat(transactionPoolConfigCaptor.getValue().getTxFeeCap()).isEqualTo(txFeeCap);
Expand Down
2 changes: 1 addition & 1 deletion config/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ dependencies {
implementation 'com.google.guava:guava'
implementation 'org.apache.logging.log4j:log4j-api'
implementation 'info.picocli:picocli'
implementation 'org.apache.tuweni:bytes'
implementation 'org.apache.tuweni:tuweni-bytes'
runtimeOnly 'org.apache.logging.log4j:log4j-core'

testImplementation project(':testutil')
Expand Down
4 changes: 2 additions & 2 deletions consensus/clique/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ dependencies {

implementation 'com.google.guava:guava'
implementation 'io.vertx:vertx-core'
implementation 'org.apache.tuweni:bytes'
implementation 'org.apache.tuweni:units'
implementation 'org.apache.tuweni:tuweni-bytes'
implementation 'org.apache.tuweni:tuweni-units'

testImplementation project(path: ':consensus:common', configuration: 'testArtifacts')
testImplementation project(path: ':crypto', configuration: 'testSupportArtifacts')
Expand Down
2 changes: 1 addition & 1 deletion consensus/common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ dependencies {

implementation 'com.fasterxml.jackson.core:jackson-databind'
implementation 'com.google.guava:guava'
implementation 'org.apache.tuweni:bytes'
implementation 'org.apache.tuweni:tuweni-bytes'

testImplementation project(':config')
testImplementation project(':crypto')
Expand Down
4 changes: 2 additions & 2 deletions consensus/ibft/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ dependencies {

implementation 'com.google.guava:guava'
implementation 'io.vertx:vertx-core'
implementation 'org.apache.tuweni:bytes'
implementation 'org.apache.tuweni:units'
implementation 'org.apache.tuweni:tuweni-bytes'
implementation 'org.apache.tuweni:tuweni-units'

integrationTestImplementation project(path: ':config', configuration: 'testSupportArtifacts')
integrationTestImplementation project(path: ':ethereum:core', configuration: 'testSupportArtifacts')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ private static List<NodeKey> committersNodeKeys() {
i ->
NodeKeyUtils.createFrom(
(signatureAlgorithm.createKeyPair(
signatureAlgorithm.createPrivateKey(UInt256.valueOf(i).toBytes())))))
signatureAlgorithm.createPrivateKey(UInt256.valueOf(i))))))
.collect(Collectors.toList());
}

Expand Down
4 changes: 2 additions & 2 deletions consensus/ibftlegacy/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ dependencies {

implementation 'com.google.guava:guava'
implementation 'io.vertx:vertx-core'
implementation 'org.apache.tuweni:bytes'
implementation 'org.apache.tuweni:units'
implementation 'org.apache.tuweni:tuweni-bytes'
implementation 'org.apache.tuweni:tuweni-units'

testImplementation project(path: ':consensus:common', configuration: 'testSupportArtifacts')
testImplementation project(path: ':consensus:ibft', configuration: 'testSupportArtifacts')
Expand Down
6 changes: 3 additions & 3 deletions consensus/qbft/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ dependencies {

implementation 'com.google.guava:guava'
implementation 'io.vertx:vertx-core'
implementation 'org.apache.tuweni:bytes'
implementation 'org.apache.tuweni:units'
implementation 'org.apache.tuweni:tuweni-bytes'
implementation 'org.apache.tuweni:tuweni-units'

integrationTestImplementation project(path: ':config', configuration: 'testSupportArtifacts')
integrationTestImplementation project(path: ':ethereum:core', configuration: 'testSupportArtifacts')
Expand Down Expand Up @@ -103,7 +103,7 @@ dependencies {
referenceTestImplementation 'org.mockito:mockito-core'
referenceTestImplementation 'com.fasterxml.jackson.core:jackson-databind'
referenceTestImplementation 'com.fasterxml.jackson.datatype:jackson-datatype-jdk8'
referenceTestImplementation 'org.apache.tuweni:bytes'
referenceTestImplementation 'org.apache.tuweni:tuweni-bytes'
referenceTestImplementation project(':crypto')
referenceTestImplementation project(path: ':crypto', configuration: 'testSupportArtifacts')
referenceTestImplementation project(':consensus:common')
Expand Down
4 changes: 2 additions & 2 deletions crypto/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ dependencies {
implementation 'com.google.guava:guava'
implementation 'net.java.dev.jna:jna'
implementation 'org.apache.logging.log4j:log4j-api'
implementation 'org.apache.tuweni:bytes'
implementation 'org.apache.tuweni:units'
implementation 'org.apache.tuweni:tuweni-bytes'
implementation 'org.apache.tuweni:tuweni-units'
implementation 'org.hyperledger.besu:secp256k1'

runtimeOnly 'org.apache.logging.log4j:log4j-core'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public Bytes32 calculateECDHKeyAgreement(
agreement.init(privKeyP);
final BigInteger agreed = agreement.calculateAgreement(pubKeyP);

return UInt256.valueOf(agreed).toBytes();
return UInt256.valueOf(agreed);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ private SECPPrivateKey(final Bytes32 encoded, final String algorithm) {

public static SECPPrivateKey create(final BigInteger key, final String algorithm) {
checkNotNull(key);
return create(UInt256.valueOf(key).toBytes(), algorithm);
return create(UInt256.valueOf(key), algorithm);
}

public static SECPPrivateKey create(final Bytes32 key, final String algorithm) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ public Bytes encodedBytes() {

private Bytes _encodedBytes() {
final MutableBytes bytes = MutableBytes.create(BYTES_REQUIRED);
UInt256.valueOf(r).toBytes().copyTo(bytes, 0);
UInt256.valueOf(s).toBytes().copyTo(bytes, 32);
UInt256.valueOf(r).copyTo(bytes, 0);
UInt256.valueOf(s).copyTo(bytes, 32);
bytes.set(64, recId);
return bytes;
}
Expand Down
2 changes: 1 addition & 1 deletion enclave/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ dependencies {
implementation 'com.fasterxml.jackson.core:jackson-databind'
implementation 'com.google.guava:guava'
implementation 'io.vertx:vertx-core'
implementation 'org.apache.tuweni:net'
implementation 'org.apache.tuweni:tuweni-net'
implementation 'org.apache.logging.log4j:log4j-api'

runtimeOnly('org.bouncycastle:bcpkix-jdk15on')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ HttpServer create(
web3HttpServerOptions.setSsl(true);
web3HttpServerOptions.setClientAuth(ClientAuth.REQUIRED);
web3HttpServerOptions.setTrustOptions(
VertxTrustOptions.whitelistClients(serverFingerprintFile));
VertxTrustOptions.allowlistClients(serverFingerprintFile));
web3HttpServerOptions.setPfxKeyCertOptions(
new PfxOptions()
.setPath(serverCert.getPkcs12File().toString())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ private HttpClientOptions createTlsClientOptions(
convertFrom(privacyKeyStoreFile, privacyKeyStorePasswordFile));
}
clientOptions.setTrustOptions(
VertxTrustOptions.whitelistServers(privacyAllowlistFile, TRUST_CA));
VertxTrustOptions.allowlistServers(privacyAllowlistFile, TRUST_CA));
} catch (final NoSuchFileException e) {
throw new InvalidConfigurationException(
"Requested file " + e.getMessage() + " does not exist at specified location.");
Expand Down
8 changes: 4 additions & 4 deletions ethereum/api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ dependencies {
implementation 'io.vertx:vertx-unit'
implementation 'io.vertx:vertx-web'
implementation 'org.apache.logging.log4j:log4j-core'
implementation 'org.apache.tuweni:bytes'
implementation 'org.apache.tuweni:net'
implementation 'org.apache.tuweni:toml'
implementation 'org.apache.tuweni:units'
implementation 'org.apache.tuweni:tuweni-bytes'
implementation 'org.apache.tuweni:tuweni-net'
implementation 'org.apache.tuweni:tuweni-toml'
implementation 'org.apache.tuweni:tuweni-units'
implementation 'org.bouncycastle:bcprov-jdk15on'
implementation 'org.springframework.security:spring-security-crypto'
implementation 'org.xerial.snappy:snappy-java'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@ public Optional<Bytes> getCode() {

public Optional<Bytes32> getStorage(final DataFetchingEnvironment environment) {
final Bytes32 slot = environment.getArgument("slot");
return Optional.of(account.getStorageValue(UInt256.fromBytes(slot)).toBytes());
return Optional.of(account.getStorageValue(UInt256.fromBytes(slot)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.collect.Streams.stream;
import static java.util.stream.Collectors.toList;
import static org.apache.tuweni.net.tls.VertxTrustOptions.whitelistClients;
import static org.apache.tuweni.net.tls.VertxTrustOptions.allowlistClients;
import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcError.INVALID_REQUEST;

import org.hyperledger.besu.ethereum.api.handlers.HandlerFactory;
Expand Down Expand Up @@ -430,7 +430,7 @@ private void applyTlsClientAuth(
.ifPresent(
knownClientsFile ->
httpServerOptions.setTrustOptions(
whitelistClients(
allowlistClients(
knownClientsFile, clientAuthConfiguration.isCaClientsEnabled())));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ private static Map<String, String> formatStorage(final Map<UInt256, UInt256> sto
final Map<String, String> formattedStorage = new TreeMap<>();
storage.forEach(
(key, value) ->
formattedStorage.put(
key.toBytes().toUnprefixedHexString(), value.toBytes().toUnprefixedHexString()));
formattedStorage.put(key.toUnprefixedHexString(), value.toUnprefixedHexString()));
return formattedStorage;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public StorageEntryProof(final UInt256 key, final UInt256 value, final List<Byte

@JsonGetter(value = "key")
public String getKey() {
return key.toString();
return key.toDecimalString();
}

@JsonGetter(value = "value")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ private void generateTracingStorage(final VmOperationExecutionReport report) {
entry ->
report.setStore(
new Store(
entry.getOffset().toBytes().toQuantityHexString(),
entry.getOffset().toQuantityHexString(),
entry.getValue().toQuantityHexString())));
}

Expand Down
4 changes: 2 additions & 2 deletions ethereum/blockcreation/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ dependencies {

implementation 'com.google.guava:guava'
implementation 'io.vertx:vertx-core'
implementation 'org.apache.tuweni:bytes'
implementation 'org.apache.tuweni:units'
implementation 'org.apache.tuweni:tuweni-bytes'
implementation 'org.apache.tuweni:tuweni-units'

testImplementation project(path: ':config', configuration: 'testSupportArtifacts')
testImplementation project(path: ':ethereum:core', configuration: 'testArtifacts')
Expand Down
10 changes: 5 additions & 5 deletions ethereum/core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ dependencies {
implementation 'io.vertx:vertx-core'
implementation 'net.java.dev.jna:jna'
implementation 'org.apache.logging.log4j:log4j-api'
implementation 'org.apache.tuweni:bytes'
implementation 'org.apache.tuweni:units'
implementation 'org.apache.tuweni:tuweni-bytes'
implementation 'org.apache.tuweni:tuweni-units'
implementation 'org.hyperledger.besu:bls12-381'
implementation 'org.immutables:value-annotations'

Expand All @@ -63,9 +63,9 @@ dependencies {

testImplementation 'junit:junit'
testImplementation 'org.apache.logging.log4j:log4j-core'
testImplementation 'org.apache.tuweni:bytes'
testImplementation 'org.apache.tuweni:io'
testImplementation 'org.apache.tuweni:units'
testImplementation 'org.apache.tuweni:tuweni-bytes'
testImplementation 'org.apache.tuweni:tuweni-io'
testImplementation 'org.apache.tuweni:tuweni-units'
testImplementation 'org.assertj:assertj-core'
testImplementation 'org.mockito:mockito-core'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,6 @@ private void addExpectedValue(
final UInt256 key,
final UInt256 value) {
account.setStorageValue(key, value);
expectedValues.put(Hash.hash(key.toBytes()), AccountStorageEntry.forKeyAndValue(key, value));
expectedValues.put(Hash.hash(key), AccountStorageEntry.forKeyAndValue(key, value));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void cleanUp() throws Exception {

@Benchmark
public Bytes32 executeOperation() {
frame.pushStackItem(UInt256.valueOf(blockNumber).toBytes());
frame.pushStackItem(UInt256.valueOf(blockNumber));
operation.execute(frame, null);
return frame.popStackItem();
}
Expand All @@ -67,7 +67,7 @@ public Bytes32 executeOperationWithEmptyHashCache() {
.createMessageFrameBuilder()
.blockHashLookup(new BlockHashLookup(frame.getBlockHeader(), frame.getBlockchain()))
.build();
cleanFrame.pushStackItem(UInt256.valueOf(blockNumber).toBytes());
cleanFrame.pushStackItem(UInt256.valueOf(blockNumber));
operation.execute(cleanFrame, null);
return cleanFrame.popStackItem();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public Optional<Bytes> getStateTrieNode(final Bytes location) {

@Override
public UInt256 getStorageValue(final Address address, final UInt256 key) {
return getStorageValueBySlotHash(address, Hash.hash(key.toBytes())).orElse(UInt256.ZERO);
return getStorageValueBySlotHash(address, Hash.hash(key)).orElse(UInt256.ZERO);
}

@Override
Expand Down Expand Up @@ -180,7 +180,7 @@ public Map<Bytes32, Bytes> getAllAccountStorage(final Address address, final Has
if (!results.containsKey(entry.getKey())) {
final UInt256 value = entry.getValue().getUpdated();
// yes, store the nulls. If it was deleted it should stay deleted
results.put(entry.getKey(), value == null ? null : value.toBytes());
results.put(entry.getKey(), value == null ? null : value);
}
});
}
Expand All @@ -196,7 +196,7 @@ public Map<Bytes32, Bytes> getAllAccountStorage(final Address address, final Has
.forEach(
(k, v) -> {
if (!results.containsKey(k)) {
results.put(k, v.getValue().toBytes());
results.put(k, v.getValue());
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,8 @@ protected Hash calculateRootHash(
stateUpdater.removeStorageValueBySlotHash(updatedAddressHash, keyHash);
storageTrie.remove(keyHash);
} else {
final Bytes32 updatedStorageBytes = updatedStorage.toBytes();
stateUpdater.putStorageValueBySlotHash(
updatedAddressHash, keyHash, updatedStorageBytes);
storageTrie.put(keyHash, BonsaiWorldView.encodeTrieValue(updatedStorageBytes));
stateUpdater.putStorageValueBySlotHash(updatedAddressHash, keyHash, updatedStorage);
storageTrie.put(keyHash, BonsaiWorldView.encodeTrieValue(updatedStorage));
}
}

Expand Down Expand Up @@ -391,7 +389,7 @@ public Optional<Bytes> getStateTrieNode(final Bytes location) {

@Override
public UInt256 getStorageValue(final Address address, final UInt256 storageKey) {
return getStorageValueBySlotHash(address, Hash.hash(storageKey.toBytes())).orElse(UInt256.ZERO);
return getStorageValueBySlotHash(address, Hash.hash(storageKey)).orElse(UInt256.ZERO);
}

@Override
Expand Down
Loading

0 comments on commit 11f5cfb

Please sign in to comment.