mirror of
https://github.com/vacp2p/status-linea-besu.git
synced 2026-01-09 15:28:09 -05:00
Move to Apache Tuweni Bytes library (#215)
Signed-off-by: Antoine Toulme <antoine@lunar-ocean.com> Signed-off-by: Danno Ferrin <danno.ferrin@gmail.com>
This commit is contained in:
committed by
Adrian Sutton
parent
f2a3c00d1b
commit
ccefada736
@@ -38,7 +38,7 @@ Simple does not mean the fewest lines of code. Simple code is:
|
||||
|
||||
Besu embraces typical Java idioms including using an Object Oriented approach to design. This includes:
|
||||
* Providing alternate behaviours via polymorphism instead of having conditional logic scattered through the codebase. For example, `ProtocolSpec` provides a standard interface to blockchain operations and multiple implementations define the different behaviours for each Ethereum milestone.
|
||||
* Encapsulating behaviour and data together in classes. For example, `BytesValue` encapsulates byte data and methods operating on the byte data. `BytesValue.isZero()` is an instance method instead of accepting a `BytesValue` parameter.
|
||||
* Encapsulating behaviour and data together in classes. For example, `Bytes` encapsulates byte data and methods operating on the byte data. `Bytes.isZero()` is an instance method instead of accepting a `Bytes` parameter.
|
||||
|
||||
`ProtocolSpec` is an exception and does not hold the blockchain data on which it operates. This is because that blockchain data is widely shared and not specifically owned by `ProtocolSpec`.
|
||||
* Embracing modern Java features like Optional, Streams and lambdas when they make code simpler and clearer.
|
||||
|
||||
@@ -32,6 +32,9 @@ dependencies {
|
||||
implementation 'io.vertx:vertx-core'
|
||||
implementation 'junit:junit'
|
||||
implementation 'net.consensys:orion'
|
||||
|
||||
implementation 'org.apache.tuweni:tuweni-bytes'
|
||||
implementation 'org.apache.tuweni:tuweni-units'
|
||||
implementation 'org.apache.logging.log4j:log4j-api'
|
||||
implementation 'org.assertj:assertj-core'
|
||||
implementation 'org.awaitility:awaitility'
|
||||
|
||||
@@ -21,9 +21,9 @@ import org.hyperledger.besu.ethereum.core.BlockHeader;
|
||||
import org.hyperledger.besu.ethereum.core.BlockHeaderFunctions;
|
||||
import org.hyperledger.besu.ethereum.core.Hash;
|
||||
import org.hyperledger.besu.ethereum.core.LogsBloomFilter;
|
||||
import org.hyperledger.besu.util.bytes.BytesValue;
|
||||
import org.hyperledger.besu.util.uint.UInt256;
|
||||
|
||||
import org.apache.tuweni.bytes.Bytes;
|
||||
import org.apache.tuweni.units.bigints.UInt256;
|
||||
import org.web3j.protocol.core.methods.response.EthBlock.Block;
|
||||
|
||||
public class BlockUtils {
|
||||
@@ -47,7 +47,7 @@ public class BlockUtils {
|
||||
block.getGasLimit().longValue(),
|
||||
block.getGasUsed().longValue(),
|
||||
block.getTimestamp().longValue(),
|
||||
BytesValue.fromHexString(block.getExtraData()),
|
||||
Bytes.fromHexString(block.getExtraData()),
|
||||
mixHash,
|
||||
block.getNonce().longValue(),
|
||||
blockHeaderFunctions);
|
||||
|
||||
@@ -23,11 +23,11 @@ import org.hyperledger.besu.tests.acceptance.dsl.condition.Condition;
|
||||
import org.hyperledger.besu.tests.acceptance.dsl.condition.account.ExpectAccountBalance;
|
||||
import org.hyperledger.besu.tests.acceptance.dsl.condition.account.ExpectAccountBalanceNotChanging;
|
||||
import org.hyperledger.besu.tests.acceptance.dsl.transaction.eth.EthTransactions;
|
||||
import org.hyperledger.besu.util.bytes.Bytes32;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
|
||||
import org.apache.tuweni.bytes.Bytes32;
|
||||
import org.web3j.crypto.Credentials;
|
||||
import org.web3j.utils.Convert.Unit;
|
||||
|
||||
|
||||
@@ -17,8 +17,6 @@ package org.hyperledger.besu.tests.acceptance.dsl.blockchain;
|
||||
import static org.web3j.utils.Convert.Unit.ETHER;
|
||||
import static org.web3j.utils.Convert.Unit.WEI;
|
||||
|
||||
import org.hyperledger.besu.ethereum.core.Wei;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
|
||||
@@ -43,10 +41,6 @@ public class Amount {
|
||||
return new Amount(new BigDecimal(value), WEI);
|
||||
}
|
||||
|
||||
public static Amount wei(final Wei wei) {
|
||||
return wei(new BigInteger(wei.toUnprefixedHexString(), 16));
|
||||
}
|
||||
|
||||
public BigDecimal getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -22,20 +22,18 @@ import org.hyperledger.besu.ethereum.core.Hash;
|
||||
import org.hyperledger.besu.tests.acceptance.dsl.account.Account;
|
||||
import org.hyperledger.besu.tests.acceptance.dsl.transaction.NodeRequests;
|
||||
import org.hyperledger.besu.tests.acceptance.dsl.transaction.Transaction;
|
||||
import org.hyperledger.besu.util.bytes.BytesValue;
|
||||
import org.hyperledger.besu.util.bytes.BytesValues;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.math.BigInteger;
|
||||
|
||||
import org.apache.tuweni.bytes.Bytes;
|
||||
import org.web3j.crypto.RawTransaction;
|
||||
import org.web3j.crypto.TransactionEncoder;
|
||||
|
||||
public class AccountSmartContractPermissioningAllowAccountTransaction implements Transaction<Hash> {
|
||||
|
||||
private static final BytesValue ADD_ACCOUNT_SIGNATURE =
|
||||
org.hyperledger.besu.crypto.Hash.keccak256(
|
||||
BytesValue.of("addAccount(address)".getBytes(UTF_8)))
|
||||
private static final Bytes ADD_ACCOUNT_SIGNATURE =
|
||||
org.hyperledger.besu.crypto.Hash.keccak256(Bytes.of("addAccount(address)".getBytes(UTF_8)))
|
||||
.slice(0, 4);
|
||||
|
||||
private final Account sender;
|
||||
@@ -62,9 +60,9 @@ public class AccountSmartContractPermissioningAllowAccountTransaction implements
|
||||
}
|
||||
|
||||
private String signedTransactionData() {
|
||||
final BytesValue payload =
|
||||
BytesValues.concatenate(
|
||||
ADD_ACCOUNT_SIGNATURE, BytesValue.fromHexString("0x000000000000000000000000"), account);
|
||||
final Bytes payload =
|
||||
Bytes.concatenate(
|
||||
ADD_ACCOUNT_SIGNATURE, Bytes.fromHexString("0x000000000000000000000000"), account);
|
||||
|
||||
final RawTransaction transaction =
|
||||
RawTransaction.createTransaction(
|
||||
|
||||
@@ -22,21 +22,19 @@ import org.hyperledger.besu.ethereum.core.Hash;
|
||||
import org.hyperledger.besu.tests.acceptance.dsl.account.Account;
|
||||
import org.hyperledger.besu.tests.acceptance.dsl.transaction.NodeRequests;
|
||||
import org.hyperledger.besu.tests.acceptance.dsl.transaction.Transaction;
|
||||
import org.hyperledger.besu.util.bytes.BytesValue;
|
||||
import org.hyperledger.besu.util.bytes.BytesValues;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.math.BigInteger;
|
||||
|
||||
import org.apache.tuweni.bytes.Bytes;
|
||||
import org.web3j.crypto.RawTransaction;
|
||||
import org.web3j.crypto.TransactionEncoder;
|
||||
|
||||
public class AccountSmartContractPermissioningForbidAccountTransaction
|
||||
implements Transaction<Hash> {
|
||||
|
||||
private static final BytesValue REMOVE_ACCOUNT_SIGNATURE =
|
||||
org.hyperledger.besu.crypto.Hash.keccak256(
|
||||
BytesValue.of("removeAccount(address)".getBytes(UTF_8)))
|
||||
private static final Bytes REMOVE_ACCOUNT_SIGNATURE =
|
||||
org.hyperledger.besu.crypto.Hash.keccak256(Bytes.of("removeAccount(address)".getBytes(UTF_8)))
|
||||
.slice(0, 4);
|
||||
|
||||
private final Account sender;
|
||||
@@ -63,11 +61,9 @@ public class AccountSmartContractPermissioningForbidAccountTransaction
|
||||
}
|
||||
|
||||
private String signedTransactionData() {
|
||||
final BytesValue payload =
|
||||
BytesValues.concatenate(
|
||||
REMOVE_ACCOUNT_SIGNATURE,
|
||||
BytesValue.fromHexString("0x000000000000000000000000"),
|
||||
account);
|
||||
final Bytes payload =
|
||||
Bytes.concatenate(
|
||||
REMOVE_ACCOUNT_SIGNATURE, Bytes.fromHexString("0x000000000000000000000000"), account);
|
||||
|
||||
RawTransaction transaction =
|
||||
RawTransaction.createTransaction(
|
||||
|
||||
@@ -20,17 +20,16 @@ import org.hyperledger.besu.crypto.Hash;
|
||||
import org.hyperledger.besu.ethereum.core.Address;
|
||||
import org.hyperledger.besu.tests.acceptance.dsl.transaction.NodeRequests;
|
||||
import org.hyperledger.besu.tests.acceptance.dsl.transaction.Transaction;
|
||||
import org.hyperledger.besu.util.bytes.BytesValue;
|
||||
import org.hyperledger.besu.util.bytes.BytesValues;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.tuweni.bytes.Bytes;
|
||||
import org.web3j.protocol.core.DefaultBlockParameterName;
|
||||
|
||||
public class AccountSmartContractPermissioningIsAllowedTransaction implements Transaction<Boolean> {
|
||||
|
||||
private static final BytesValue IS_ACCOUNT_ALLOWED_SIGNATURE =
|
||||
Hash.keccak256(BytesValue.of("whitelistContains(address)".getBytes(UTF_8))).slice(0, 4);
|
||||
private static final Bytes IS_ACCOUNT_ALLOWED_SIGNATURE =
|
||||
Hash.keccak256(Bytes.of("whitelistContains(address)".getBytes(UTF_8))).slice(0, 4);
|
||||
|
||||
private final Address contractAddress;
|
||||
private final Address account;
|
||||
@@ -46,7 +45,7 @@ public class AccountSmartContractPermissioningIsAllowedTransaction implements Tr
|
||||
try {
|
||||
final String value =
|
||||
node.eth().ethCall(payload(), DefaultBlockParameterName.LATEST).send().getValue();
|
||||
return checkTransactionResult(BytesValue.fromHexString(value));
|
||||
return checkTransactionResult(Bytes.fromHexString(value));
|
||||
} catch (final IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
@@ -54,23 +53,21 @@ public class AccountSmartContractPermissioningIsAllowedTransaction implements Tr
|
||||
|
||||
// Checks the returned bytes from the permissioning contract call to see if it's a value we
|
||||
// understand
|
||||
static Boolean checkTransactionResult(final BytesValue result) {
|
||||
static Boolean checkTransactionResult(final Bytes result) {
|
||||
// booleans are padded to 32 bytes
|
||||
if (result.size() != 32) {
|
||||
throw new IllegalArgumentException("Unexpected result size");
|
||||
}
|
||||
|
||||
// 0 is false
|
||||
if (result.compareTo(
|
||||
BytesValue.fromHexString(
|
||||
"0x0000000000000000000000000000000000000000000000000000000000000000"))
|
||||
== 0) {
|
||||
if (result.equals(
|
||||
Bytes.fromHexString(
|
||||
"0x0000000000000000000000000000000000000000000000000000000000000000"))) {
|
||||
return false;
|
||||
// 1 filled to 32 bytes is true
|
||||
} else if (result.compareTo(
|
||||
BytesValue.fromHexString(
|
||||
"0x0000000000000000000000000000000000000000000000000000000000000001"))
|
||||
== 0) {
|
||||
} else if (result.equals(
|
||||
Bytes.fromHexString(
|
||||
"0x0000000000000000000000000000000000000000000000000000000000000001"))) {
|
||||
return true;
|
||||
// Anything else is wrong
|
||||
} else {
|
||||
@@ -79,10 +76,10 @@ public class AccountSmartContractPermissioningIsAllowedTransaction implements Tr
|
||||
}
|
||||
|
||||
private org.web3j.protocol.core.methods.request.Transaction payload() {
|
||||
final BytesValue payload =
|
||||
BytesValues.concatenate(
|
||||
final Bytes payload =
|
||||
Bytes.concatenate(
|
||||
IS_ACCOUNT_ALLOWED_SIGNATURE,
|
||||
BytesValue.fromHexString("0x000000000000000000000000"),
|
||||
Bytes.fromHexString("0x000000000000000000000000"),
|
||||
account);
|
||||
|
||||
return org.web3j.protocol.core.methods.request.Transaction.createFunctionCallTransaction(
|
||||
|
||||
@@ -26,19 +26,19 @@ import org.hyperledger.besu.tests.acceptance.dsl.node.Node;
|
||||
import org.hyperledger.besu.tests.acceptance.dsl.node.RunnableNode;
|
||||
import org.hyperledger.besu.tests.acceptance.dsl.transaction.NodeRequests;
|
||||
import org.hyperledger.besu.tests.acceptance.dsl.transaction.Transaction;
|
||||
import org.hyperledger.besu.util.bytes.BytesValue;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.math.BigInteger;
|
||||
|
||||
import org.apache.tuweni.bytes.Bytes;
|
||||
import org.web3j.crypto.RawTransaction;
|
||||
import org.web3j.crypto.TransactionEncoder;
|
||||
|
||||
public class NodeSmartContractPermissioningAllowNodeTransaction implements Transaction<Hash> {
|
||||
|
||||
private static final BytesValue ADD_ENODE_SIGNATURE =
|
||||
private static final Bytes ADD_ENODE_SIGNATURE =
|
||||
org.hyperledger.besu.crypto.Hash.keccak256(
|
||||
BytesValue.of("addEnode(bytes32,bytes32,bytes16,uint16)".getBytes(UTF_8)))
|
||||
Bytes.of("addEnode(bytes32,bytes32,bytes16,uint16)".getBytes(UTF_8)))
|
||||
.slice(0, 4);
|
||||
|
||||
private final Account sender;
|
||||
@@ -66,7 +66,7 @@ public class NodeSmartContractPermissioningAllowNodeTransaction implements Trans
|
||||
|
||||
private String signedTransactionData() {
|
||||
final String enodeURL = ((RunnableNode) node).enodeUrl().toASCIIString();
|
||||
final BytesValue payload =
|
||||
final Bytes payload =
|
||||
NodeSmartContractPermissioningController.createPayload(
|
||||
ADD_ENODE_SIGNATURE, EnodeURL.fromString(enodeURL));
|
||||
|
||||
|
||||
@@ -25,18 +25,18 @@ import org.hyperledger.besu.tests.acceptance.dsl.node.Node;
|
||||
import org.hyperledger.besu.tests.acceptance.dsl.node.RunnableNode;
|
||||
import org.hyperledger.besu.tests.acceptance.dsl.transaction.NodeRequests;
|
||||
import org.hyperledger.besu.tests.acceptance.dsl.transaction.Transaction;
|
||||
import org.hyperledger.besu.util.bytes.BytesValue;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.tuweni.bytes.Bytes;
|
||||
import org.web3j.protocol.core.DefaultBlockParameterName;
|
||||
|
||||
public class NodeSmartContractPermissioningConnectionIsAllowedTransaction
|
||||
implements Transaction<Boolean> {
|
||||
|
||||
private static final BytesValue IS_CONNECTION_ALLOWED_SIGNATURE =
|
||||
private static final Bytes IS_CONNECTION_ALLOWED_SIGNATURE =
|
||||
Hash.keccak256(
|
||||
BytesValue.of(
|
||||
Bytes.of(
|
||||
"connectionAllowed(bytes32,bytes32,bytes16,uint16,bytes32,bytes32,bytes16,uint16)"
|
||||
.getBytes(UTF_8)))
|
||||
.slice(0, 4);
|
||||
@@ -57,7 +57,7 @@ public class NodeSmartContractPermissioningConnectionIsAllowedTransaction
|
||||
try {
|
||||
final String value =
|
||||
node.eth().ethCall(payload(), DefaultBlockParameterName.LATEST).send().getValue();
|
||||
return checkTransactionResult(BytesValue.fromHexString(value));
|
||||
return checkTransactionResult(Bytes.fromHexString(value));
|
||||
} catch (final IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
@@ -66,7 +66,7 @@ public class NodeSmartContractPermissioningConnectionIsAllowedTransaction
|
||||
private org.web3j.protocol.core.methods.request.Transaction payload() {
|
||||
final String sourceEnodeURL = ((RunnableNode) source).enodeUrl().toASCIIString();
|
||||
final String targetEnodeURL = ((RunnableNode) target).enodeUrl().toASCIIString();
|
||||
final BytesValue payload =
|
||||
final Bytes payload =
|
||||
NodeSmartContractPermissioningController.createPayload(
|
||||
IS_CONNECTION_ALLOWED_SIGNATURE,
|
||||
EnodeURL.fromString(sourceEnodeURL),
|
||||
|
||||
@@ -26,19 +26,19 @@ import org.hyperledger.besu.tests.acceptance.dsl.node.Node;
|
||||
import org.hyperledger.besu.tests.acceptance.dsl.node.RunnableNode;
|
||||
import org.hyperledger.besu.tests.acceptance.dsl.transaction.NodeRequests;
|
||||
import org.hyperledger.besu.tests.acceptance.dsl.transaction.Transaction;
|
||||
import org.hyperledger.besu.util.bytes.BytesValue;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.math.BigInteger;
|
||||
|
||||
import org.apache.tuweni.bytes.Bytes;
|
||||
import org.web3j.crypto.RawTransaction;
|
||||
import org.web3j.crypto.TransactionEncoder;
|
||||
|
||||
public class NodeSmartContractPermissioningForbidNodeTransaction implements Transaction<Hash> {
|
||||
|
||||
private static final BytesValue REMOVE_ENODE_SIGNATURE =
|
||||
private static final Bytes REMOVE_ENODE_SIGNATURE =
|
||||
org.hyperledger.besu.crypto.Hash.keccak256(
|
||||
BytesValue.of("removeEnode(bytes32,bytes32,bytes16,uint16)".getBytes(UTF_8)))
|
||||
Bytes.of("removeEnode(bytes32,bytes32,bytes16,uint16)".getBytes(UTF_8)))
|
||||
.slice(0, 4);
|
||||
|
||||
private final Account sender;
|
||||
@@ -66,7 +66,7 @@ public class NodeSmartContractPermissioningForbidNodeTransaction implements Tran
|
||||
|
||||
private String signedTransactionData() {
|
||||
final String enodeURL = ((RunnableNode) node).enodeUrl().toASCIIString();
|
||||
final BytesValue payload =
|
||||
final Bytes payload =
|
||||
NodeSmartContractPermissioningController.createPayload(
|
||||
REMOVE_ENODE_SIGNATURE, EnodeURL.fromString(enodeURL));
|
||||
|
||||
|
||||
@@ -24,16 +24,16 @@ import org.hyperledger.besu.tests.acceptance.dsl.node.Node;
|
||||
import org.hyperledger.besu.tests.acceptance.dsl.node.RunnableNode;
|
||||
import org.hyperledger.besu.tests.acceptance.dsl.transaction.NodeRequests;
|
||||
import org.hyperledger.besu.tests.acceptance.dsl.transaction.Transaction;
|
||||
import org.hyperledger.besu.util.bytes.BytesValue;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.tuweni.bytes.Bytes;
|
||||
import org.web3j.protocol.core.DefaultBlockParameterName;
|
||||
|
||||
public class NodeSmartContractPermissioningIsAllowedTransaction implements Transaction<Boolean> {
|
||||
|
||||
private static final BytesValue IS_NODE_ALLOWED_SIGNATURE =
|
||||
Hash.keccak256(BytesValue.of("enodeAllowed(bytes32,bytes32,bytes16,uint16)".getBytes(UTF_8)))
|
||||
private static final Bytes IS_NODE_ALLOWED_SIGNATURE =
|
||||
Hash.keccak256(Bytes.of("enodeAllowed(bytes32,bytes32,bytes16,uint16)".getBytes(UTF_8)))
|
||||
.slice(0, 4);
|
||||
|
||||
private final Address contractAddress;
|
||||
@@ -50,7 +50,7 @@ public class NodeSmartContractPermissioningIsAllowedTransaction implements Trans
|
||||
try {
|
||||
final String value =
|
||||
node.eth().ethCall(payload(), DefaultBlockParameterName.LATEST).send().getValue();
|
||||
return checkTransactionResult(BytesValue.fromHexString(value));
|
||||
return checkTransactionResult(Bytes.fromHexString(value));
|
||||
} catch (final IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
@@ -58,23 +58,21 @@ public class NodeSmartContractPermissioningIsAllowedTransaction implements Trans
|
||||
|
||||
// Checks the returned bytes from the permissioning contract call to see if it's a value we
|
||||
// understand
|
||||
static Boolean checkTransactionResult(final BytesValue result) {
|
||||
static Boolean checkTransactionResult(final Bytes result) {
|
||||
// booleans are padded to 32 bytes
|
||||
if (result.size() != 32) {
|
||||
throw new IllegalArgumentException("Unexpected result size");
|
||||
}
|
||||
|
||||
// 0 is false
|
||||
if (result.compareTo(
|
||||
BytesValue.fromHexString(
|
||||
"0x0000000000000000000000000000000000000000000000000000000000000000"))
|
||||
== 0) {
|
||||
if (result.equals(
|
||||
Bytes.fromHexString(
|
||||
"0x0000000000000000000000000000000000000000000000000000000000000000"))) {
|
||||
return false;
|
||||
// 1 filled to 32 bytes is true
|
||||
} else if (result.compareTo(
|
||||
BytesValue.fromHexString(
|
||||
"0x0000000000000000000000000000000000000000000000000000000000000001"))
|
||||
== 0) {
|
||||
} else if (result.equals(
|
||||
Bytes.fromHexString(
|
||||
"0x0000000000000000000000000000000000000000000000000000000000000001"))) {
|
||||
return true;
|
||||
// Anything else is wrong
|
||||
} else {
|
||||
@@ -84,7 +82,7 @@ public class NodeSmartContractPermissioningIsAllowedTransaction implements Trans
|
||||
|
||||
private org.web3j.protocol.core.methods.request.Transaction payload() {
|
||||
final String sourceEnodeURL = ((RunnableNode) node).enodeUrl().toASCIIString();
|
||||
final BytesValue payload =
|
||||
final Bytes payload =
|
||||
NodeSmartContractPermissioningController.createPayload(
|
||||
IS_NODE_ALLOWED_SIGNATURE, EnodeURL.fromString(sourceEnodeURL));
|
||||
|
||||
|
||||
@@ -23,14 +23,13 @@ import org.hyperledger.besu.ethereum.core.Address;
|
||||
import org.hyperledger.besu.tests.acceptance.dsl.privacy.PrivacyAcceptanceTestBase;
|
||||
import org.hyperledger.besu.tests.acceptance.dsl.privacy.PrivacyNode;
|
||||
import org.hyperledger.besu.tests.web3j.generated.EventEmitter;
|
||||
import org.hyperledger.besu.util.bytes.BytesValue;
|
||||
import org.hyperledger.besu.util.bytes.BytesValues;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
||||
import io.vertx.core.Vertx;
|
||||
import org.apache.tuweni.bytes.Bytes;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -160,14 +159,12 @@ public class PrivacyClusterAcceptanceTest extends PrivacyAcceptanceTestBase {
|
||||
final Enclave aliceEnclave = enclaveFactory.createVertxEnclave(alice.getOrion().clientUrl());
|
||||
final ReceiveResponse aliceRR =
|
||||
aliceEnclave.receive(
|
||||
BytesValues.asBase64String(BytesValue.fromHexString(transactionKey)),
|
||||
alice.getEnclaveKey());
|
||||
Bytes.fromHexString(transactionKey).toBase64String(), alice.getEnclaveKey());
|
||||
|
||||
final Enclave bobEnclave = enclaveFactory.createVertxEnclave(bob.getOrion().clientUrl());
|
||||
final ReceiveResponse bobRR =
|
||||
bobEnclave.receive(
|
||||
BytesValues.asBase64String(BytesValue.fromHexString(transactionKey)),
|
||||
bob.getEnclaveKey());
|
||||
Bytes.fromHexString(transactionKey).toBase64String(), bob.getEnclaveKey());
|
||||
|
||||
assertThat(bobRR).isEqualToComparingFieldByField(aliceRR);
|
||||
|
||||
|
||||
@@ -53,6 +53,8 @@ dependencies {
|
||||
implementation 'com.fasterxml.jackson.core:jackson-databind'
|
||||
compile group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-jdk8', version: '2.9.8'
|
||||
implementation 'com.graphql-java:graphql-java'
|
||||
implementation 'org.apache.tuweni:tuweni-bytes'
|
||||
implementation 'org.apache.tuweni:tuweni-units'
|
||||
implementation 'com.google.guava:guava'
|
||||
implementation 'info.picocli:picocli'
|
||||
implementation 'io.vertx:vertx-core'
|
||||
@@ -67,6 +69,8 @@ dependencies {
|
||||
testImplementation project(':testutil')
|
||||
testImplementation project(path: ':ethereum:core', configuration: 'testSupportArtifacts')
|
||||
|
||||
testImplementation 'org.apache.tuweni:tuweni-bytes'
|
||||
testImplementation 'org.apache.tuweni:tuweni-units'
|
||||
testImplementation 'com.squareup.okhttp3:okhttp'
|
||||
testImplementation 'com.google.auto.service:auto-service'
|
||||
testImplementation 'junit:junit'
|
||||
|
||||
@@ -89,7 +89,6 @@ import org.hyperledger.besu.metrics.prometheus.MetricsService;
|
||||
import org.hyperledger.besu.nat.NatMethod;
|
||||
import org.hyperledger.besu.nat.upnp.UpnpNatManager;
|
||||
import org.hyperledger.besu.util.NetworkUtility;
|
||||
import org.hyperledger.besu.util.bytes.BytesValue;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
@@ -106,6 +105,7 @@ import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.base.Preconditions;
|
||||
import graphql.GraphQL;
|
||||
import io.vertx.core.Vertx;
|
||||
import org.apache.tuweni.bytes.Bytes;
|
||||
|
||||
public class RunnerBuilder {
|
||||
|
||||
@@ -113,7 +113,7 @@ public class RunnerBuilder {
|
||||
private BesuController<?> besuController;
|
||||
|
||||
private NetworkingConfiguration networkingConfiguration = NetworkingConfiguration.create();
|
||||
private Collection<BytesValue> bannedNodeIds = new ArrayList<>();
|
||||
private Collection<Bytes> bannedNodeIds = new ArrayList<>();
|
||||
private boolean p2pEnabled = true;
|
||||
private boolean discovery;
|
||||
private String p2pAdvertisedHost;
|
||||
@@ -230,7 +230,7 @@ public class RunnerBuilder {
|
||||
return this;
|
||||
}
|
||||
|
||||
public RunnerBuilder bannedNodeIds(final Collection<BytesValue> bannedNodeIds) {
|
||||
public RunnerBuilder bannedNodeIds(final Collection<Bytes> bannedNodeIds) {
|
||||
this.bannedNodeIds.addAll(bannedNodeIds);
|
||||
return this;
|
||||
}
|
||||
@@ -314,7 +314,7 @@ public class RunnerBuilder {
|
||||
new TransactionSimulator(
|
||||
context.getBlockchain(), context.getWorldStateArchive(), protocolSchedule);
|
||||
|
||||
final BytesValue localNodeId = keyPair.getPublicKey().getEncodedBytes();
|
||||
final Bytes localNodeId = keyPair.getPublicKey().getEncodedBytes();
|
||||
final Optional<NodePermissioningController> nodePermissioningController =
|
||||
buildNodePermissioningController(
|
||||
bootnodes, synchronizer, transactionSimulator, localNodeId);
|
||||
@@ -516,7 +516,7 @@ public class RunnerBuilder {
|
||||
final List<EnodeURL> bootnodesAsEnodeURLs,
|
||||
final Synchronizer synchronizer,
|
||||
final TransactionSimulator transactionSimulator,
|
||||
final BytesValue localNodeId) {
|
||||
final Bytes localNodeId) {
|
||||
final Collection<EnodeURL> fixedNodes = getFixedNodes(bootnodesAsEnodeURLs, staticNodes);
|
||||
|
||||
if (permissioningConfiguration.isPresent()) {
|
||||
|
||||
@@ -17,11 +17,12 @@ package org.hyperledger.besu.chainexport;
|
||||
import org.hyperledger.besu.ethereum.chain.Blockchain;
|
||||
import org.hyperledger.besu.ethereum.core.Block;
|
||||
import org.hyperledger.besu.ethereum.rlp.RLP;
|
||||
import org.hyperledger.besu.util.bytes.BytesValue;
|
||||
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.tuweni.bytes.Bytes;
|
||||
|
||||
public class RlpBlockExporter extends BlockExporter {
|
||||
|
||||
public RlpBlockExporter(final Blockchain blockchain) {
|
||||
@@ -31,7 +32,7 @@ public class RlpBlockExporter extends BlockExporter {
|
||||
@Override
|
||||
protected void exportBlock(final FileOutputStream outputStream, final Block block)
|
||||
throws IOException {
|
||||
final BytesValue rlp = RLP.encode(block::writeTo);
|
||||
outputStream.write(rlp.getArrayUnsafe());
|
||||
final Bytes rlp = RLP.encode(block::writeTo);
|
||||
outputStream.write(rlp.toArrayUnsafe());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,6 @@ import org.hyperledger.besu.ethereum.core.Hash;
|
||||
import org.hyperledger.besu.ethereum.core.Transaction;
|
||||
import org.hyperledger.besu.ethereum.core.WorldState;
|
||||
import org.hyperledger.besu.ethereum.mainnet.HeaderValidationMode;
|
||||
import org.hyperledger.besu.util.bytes.BytesValue;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
@@ -42,6 +41,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.tuweni.bytes.Bytes;
|
||||
|
||||
/**
|
||||
* Tool for importing blocks with transactions from human-readable json.
|
||||
@@ -127,7 +127,7 @@ public class JsonBlockImporter<C> {
|
||||
// For simplicity only set these for ethash. Other consensus algorithms use these fields for
|
||||
// special purposes or ignore them
|
||||
miner.setCoinbase(blockData.getCoinbase().orElse(Address.ZERO));
|
||||
miner.setExtraData(blockData.getExtraData().orElse(BytesValue.EMPTY));
|
||||
miner.setExtraData(blockData.getExtraData().orElse(Bytes.EMPTY));
|
||||
} else if (blockData.getCoinbase().isPresent() || blockData.getExtraData().isPresent()) {
|
||||
// Fail if these fields are set for non-ethash chains
|
||||
final Stream.Builder<String> fields = Stream.builder();
|
||||
|
||||
@@ -30,7 +30,6 @@ import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
|
||||
import org.hyperledger.besu.ethereum.mainnet.ProtocolSpec;
|
||||
import org.hyperledger.besu.ethereum.mainnet.ScheduleBasedBlockHeaderFunctions;
|
||||
import org.hyperledger.besu.ethereum.util.RawBlockIterator;
|
||||
import org.hyperledger.besu.util.uint.UInt256;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
@@ -43,6 +42,7 @@ import java.util.concurrent.Semaphore;
|
||||
|
||||
import com.google.common.base.MoreObjects;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.tuweni.units.bigints.UInt256;
|
||||
|
||||
/** Tool for importing rlp-encoded block data from files. */
|
||||
public class RlpBlockImporter {
|
||||
|
||||
@@ -20,9 +20,6 @@ import org.hyperledger.besu.ethereum.core.Address;
|
||||
import org.hyperledger.besu.ethereum.core.Hash;
|
||||
import org.hyperledger.besu.ethereum.core.Transaction;
|
||||
import org.hyperledger.besu.ethereum.core.WorldState;
|
||||
import org.hyperledger.besu.util.bytes.Bytes32;
|
||||
import org.hyperledger.besu.util.bytes.BytesValue;
|
||||
import org.hyperledger.besu.util.uint.UInt256;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -32,6 +29,9 @@ import java.util.stream.Stream;
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import org.apache.tuweni.bytes.Bytes;
|
||||
import org.apache.tuweni.bytes.Bytes32;
|
||||
import org.apache.tuweni.units.bigints.UInt256;
|
||||
|
||||
@JsonIgnoreProperties("comment")
|
||||
public class BlockData {
|
||||
@@ -40,7 +40,7 @@ public class BlockData {
|
||||
private final Optional<Hash> parentHash;
|
||||
private final List<TransactionData> transactionData;
|
||||
private final Optional<Address> coinbase;
|
||||
private final Optional<BytesValue> extraData;
|
||||
private final Optional<Bytes> extraData;
|
||||
|
||||
@JsonCreator
|
||||
public BlockData(
|
||||
@@ -52,7 +52,7 @@ public class BlockData {
|
||||
this.number = number.map(UInt256::fromHexString).map(UInt256::toLong);
|
||||
this.parentHash = parentHash.map(Bytes32::fromHexString).map(Hash::wrap);
|
||||
this.coinbase = coinbase.map(Address::fromHexString);
|
||||
this.extraData = extraData.map(BytesValue::fromHexStringLenient);
|
||||
this.extraData = extraData.map(Bytes::fromHexStringLenient);
|
||||
this.transactionData = transactions;
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ public class BlockData {
|
||||
return coinbase;
|
||||
}
|
||||
|
||||
public Optional<BytesValue> getExtraData() {
|
||||
public Optional<Bytes> getExtraData() {
|
||||
return extraData;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,22 +19,22 @@ import org.hyperledger.besu.crypto.SECP256K1.PrivateKey;
|
||||
import org.hyperledger.besu.ethereum.core.Address;
|
||||
import org.hyperledger.besu.ethereum.core.Transaction;
|
||||
import org.hyperledger.besu.ethereum.core.Wei;
|
||||
import org.hyperledger.besu.util.bytes.Bytes32;
|
||||
import org.hyperledger.besu.util.bytes.BytesValue;
|
||||
import org.hyperledger.besu.util.uint.UInt256;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import org.apache.tuweni.bytes.Bytes;
|
||||
import org.apache.tuweni.bytes.Bytes32;
|
||||
import org.apache.tuweni.units.bigints.UInt256;
|
||||
|
||||
@JsonIgnoreProperties("comment")
|
||||
public class TransactionData {
|
||||
|
||||
private final long gasLimit;
|
||||
private final Wei gasPrice;
|
||||
private final BytesValue data;
|
||||
private final Bytes data;
|
||||
private final Wei value;
|
||||
private final Optional<Address> to;
|
||||
private final PrivateKey privateKey;
|
||||
@@ -49,7 +49,7 @@ public class TransactionData {
|
||||
@JsonProperty("secretKey") final String secretKey) {
|
||||
this.gasLimit = UInt256.fromHexString(gasLimit).toLong();
|
||||
this.gasPrice = Wei.fromHexString(gasPrice);
|
||||
this.data = data.map(BytesValue::fromHexString).orElse(BytesValue.EMPTY);
|
||||
this.data = data.map(Bytes::fromHexString).orElse(Bytes.EMPTY);
|
||||
this.value = value.map(Wei::fromHexString).orElse(Wei.ZERO);
|
||||
this.to = to.map(Address::fromHexString);
|
||||
this.privateKey = PrivateKey.create(Bytes32.fromHexString(secretKey));
|
||||
|
||||
@@ -115,10 +115,8 @@ import org.hyperledger.besu.services.PicoCLIOptionsImpl;
|
||||
import org.hyperledger.besu.services.StorageServiceImpl;
|
||||
import org.hyperledger.besu.util.NetworkUtility;
|
||||
import org.hyperledger.besu.util.PermissioningConfigurationValidator;
|
||||
import org.hyperledger.besu.util.bytes.BytesValue;
|
||||
import org.hyperledger.besu.util.number.Fraction;
|
||||
import org.hyperledger.besu.util.number.PositiveNumber;
|
||||
import org.hyperledger.besu.util.uint.UInt256;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -154,6 +152,8 @@ import org.apache.logging.log4j.Level;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.logging.log4j.core.config.Configurator;
|
||||
import org.apache.tuweni.bytes.Bytes;
|
||||
import org.apache.tuweni.units.bigints.UInt256;
|
||||
import picocli.CommandLine;
|
||||
import picocli.CommandLine.AbstractParseResultHandler;
|
||||
import picocli.CommandLine.Command;
|
||||
@@ -315,7 +315,7 @@ public class BesuCommand implements DefaultCommandValues, Runnable {
|
||||
}
|
||||
}
|
||||
|
||||
private Collection<BytesValue> bannedNodeIds = new ArrayList<>();
|
||||
private Collection<Bytes> bannedNodeIds = new ArrayList<>();
|
||||
|
||||
@Option(
|
||||
names = {"--sync-mode"},
|
||||
@@ -611,7 +611,7 @@ public class BesuCommand implements DefaultCommandValues, Runnable {
|
||||
"A hex string representing the (32) bytes to be included in the extra data "
|
||||
+ "field of a mined block (default: ${DEFAULT-VALUE})",
|
||||
arity = "1")
|
||||
private final BytesValue extraData = DEFAULT_EXTRA_DATA;
|
||||
private final Bytes extraData = DEFAULT_EXTRA_DATA;
|
||||
|
||||
@Option(
|
||||
names = {"--pruning-enabled"},
|
||||
@@ -868,10 +868,10 @@ public class BesuCommand implements DefaultCommandValues, Runnable {
|
||||
|
||||
private BesuCommand registerConverters() {
|
||||
commandLine.registerConverter(Address.class, Address::fromHexStringStrict);
|
||||
commandLine.registerConverter(BytesValue.class, BytesValue::fromHexString);
|
||||
commandLine.registerConverter(Bytes.class, Bytes::fromHexString);
|
||||
commandLine.registerConverter(Level.class, Level::valueOf);
|
||||
commandLine.registerConverter(SyncMode.class, SyncMode::fromString);
|
||||
commandLine.registerConverter(UInt256.class, (arg) -> UInt256.of(new BigInteger(arg)));
|
||||
commandLine.registerConverter(UInt256.class, (arg) -> UInt256.valueOf(new BigInteger(arg)));
|
||||
commandLine.registerConverter(Wei.class, (arg) -> Wei.of(Long.parseUnsignedLong(arg)));
|
||||
commandLine.registerConverter(PositiveNumber.class, PositiveNumber::fromString);
|
||||
commandLine.registerConverter(Hash.class, Hash::fromHexString);
|
||||
|
||||
@@ -18,7 +18,6 @@ import org.hyperledger.besu.ethereum.core.Wei;
|
||||
import org.hyperledger.besu.ethereum.eth.sync.SyncMode;
|
||||
import org.hyperledger.besu.ethereum.p2p.config.RlpxConfiguration;
|
||||
import org.hyperledger.besu.nat.NatMethod;
|
||||
import org.hyperledger.besu.util.bytes.BytesValue;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -28,6 +27,7 @@ import java.nio.file.InvalidPathException;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
import org.apache.tuweni.bytes.Bytes;
|
||||
import picocli.CommandLine;
|
||||
|
||||
public interface DefaultCommandValues {
|
||||
@@ -45,7 +45,7 @@ public interface DefaultCommandValues {
|
||||
String MANDATORY_NETWORK_FORMAT_HELP = "<NETWORK>";
|
||||
String MANDATORY_NODE_ID_FORMAT_HELP = "<NODEID>";
|
||||
Wei DEFAULT_MIN_TRANSACTION_GAS_PRICE = Wei.of(1000);
|
||||
BytesValue DEFAULT_EXTRA_DATA = BytesValue.EMPTY;
|
||||
Bytes DEFAULT_EXTRA_DATA = Bytes.EMPTY;
|
||||
long DEFAULT_MAX_REFRESH_DELAY = 3600000;
|
||||
long DEFAULT_MIN_REFRESH_DELAY = 1;
|
||||
String DOCKER_GENESIS_LOCATION = "/etc/besu/genesis.json";
|
||||
|
||||
@@ -16,13 +16,11 @@ package org.hyperledger.besu.cli.options;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
|
||||
import org.hyperledger.besu.util.uint.UInt256;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.util.Iterator;
|
||||
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.collect.Range;
|
||||
import org.apache.tuweni.units.bigints.UInt256;
|
||||
|
||||
public class OptionParser {
|
||||
|
||||
@@ -53,6 +51,6 @@ public class OptionParser {
|
||||
}
|
||||
|
||||
public static String format(final UInt256 value) {
|
||||
return new BigInteger(value.toUnprefixedHexString(), 16).toString(10);
|
||||
return value.toBigInteger().toString(10);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,12 +15,12 @@
|
||||
package org.hyperledger.besu.cli.options;
|
||||
|
||||
import org.hyperledger.besu.ethereum.eth.sync.SynchronizerConfiguration;
|
||||
import org.hyperledger.besu.util.uint.UInt256;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.collect.Range;
|
||||
import org.apache.tuweni.units.bigints.UInt256;
|
||||
import picocli.CommandLine;
|
||||
|
||||
public class SynchronizerOptions implements CLIOptions<SynchronizerConfiguration.Builder> {
|
||||
|
||||
@@ -32,7 +32,6 @@ import org.hyperledger.besu.ethereum.core.MiningParameters;
|
||||
import org.hyperledger.besu.ethereum.core.Wei;
|
||||
import org.hyperledger.besu.metrics.prometheus.MetricsConfiguration;
|
||||
import org.hyperledger.besu.metrics.prometheus.MetricsService;
|
||||
import org.hyperledger.besu.util.bytes.BytesValue;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
@@ -46,6 +45,7 @@ import java.util.Optional;
|
||||
import io.vertx.core.Vertx;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.tuweni.bytes.Bytes;
|
||||
import picocli.CommandLine;
|
||||
import picocli.CommandLine.Command;
|
||||
import picocli.CommandLine.ExecutionException;
|
||||
@@ -192,7 +192,7 @@ public class BlocksSubCommand implements Runnable {
|
||||
final Wei minTransactionGasPrice = Wei.ZERO;
|
||||
// Extradata and coinbase can be configured on a per-block level via the json file
|
||||
final Address coinbase = Address.ZERO;
|
||||
final BytesValue extraData = BytesValue.EMPTY;
|
||||
final Bytes extraData = Bytes.EMPTY;
|
||||
return new MiningParameters(coinbase, minTransactionGasPrice, extraData, false);
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,6 @@ import org.hyperledger.besu.consensus.ibft.IbftExtraData;
|
||||
import org.hyperledger.besu.crypto.SECP256K1;
|
||||
import org.hyperledger.besu.ethereum.core.Address;
|
||||
import org.hyperledger.besu.ethereum.core.Util;
|
||||
import org.hyperledger.besu.util.bytes.BytesValue;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -43,6 +42,7 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.google.common.io.Resources;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.tuweni.bytes.Bytes;
|
||||
import picocli.CommandLine.Command;
|
||||
import picocli.CommandLine.Option;
|
||||
import picocli.CommandLine.ParentCommand;
|
||||
@@ -154,7 +154,7 @@ class GenerateBlockchainConfig implements Runnable {
|
||||
|
||||
try {
|
||||
final SECP256K1.PublicKey publicKey =
|
||||
SECP256K1.PublicKey.create(BytesValue.fromHexString(publicKeyText));
|
||||
SECP256K1.PublicKey.create(Bytes.fromHexString(publicKeyText));
|
||||
writeKeypair(publicKey, null);
|
||||
LOG.info("Public key imported from configuration.({})", publicKey.toString());
|
||||
} catch (final IOException e) {
|
||||
|
||||
@@ -16,7 +16,6 @@ package org.hyperledger.besu.cli.subcommands.rlp;
|
||||
|
||||
import org.hyperledger.besu.consensus.ibft.IbftExtraData;
|
||||
import org.hyperledger.besu.ethereum.core.Address;
|
||||
import org.hyperledger.besu.util.bytes.BytesValue;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
@@ -24,6 +23,7 @@ import java.util.stream.Collectors;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.apache.tuweni.bytes.Bytes;
|
||||
|
||||
/**
|
||||
* Adapter to convert a typed JSON to an IbftExtraData object This adapter handles the JSON to RLP
|
||||
@@ -35,7 +35,7 @@ public class IbftExtraDataCLIAdapter implements JSONToRLP {
|
||||
new TypeReference<Collection<String>>() {};
|
||||
|
||||
@Override
|
||||
public BytesValue encode(final String json) throws IOException {
|
||||
public Bytes encode(final String json) throws IOException {
|
||||
return fromJsonAddresses(json).encode();
|
||||
}
|
||||
|
||||
|
||||
@@ -14,10 +14,10 @@
|
||||
*/
|
||||
package org.hyperledger.besu.cli.subcommands.rlp;
|
||||
|
||||
import org.hyperledger.besu.util.bytes.BytesValue;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.tuweni.bytes.Bytes;
|
||||
|
||||
/** Behaviour of objects that can be encoded from JSON to RLP */
|
||||
interface JSONToRLP {
|
||||
|
||||
@@ -28,5 +28,5 @@ interface JSONToRLP {
|
||||
* @return the RLP encoded object.
|
||||
* @throws IOException if an error occurs while reading data
|
||||
*/
|
||||
BytesValue encode(String json) throws IOException;
|
||||
Bytes encode(String json) throws IOException;
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import org.hyperledger.besu.cli.BesuCommand;
|
||||
import org.hyperledger.besu.cli.DefaultCommandValues;
|
||||
import org.hyperledger.besu.cli.subcommands.rlp.RLPSubCommand.EncodeSubCommand;
|
||||
import org.hyperledger.besu.util.bytes.BytesValue;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
@@ -33,6 +32,7 @@ import java.nio.file.Path;
|
||||
import java.util.Scanner;
|
||||
|
||||
import com.fasterxml.jackson.databind.exc.MismatchedInputException;
|
||||
import org.apache.tuweni.bytes.Bytes;
|
||||
import picocli.CommandLine.Command;
|
||||
import picocli.CommandLine.ExecutionException;
|
||||
import picocli.CommandLine.Model.CommandSpec;
|
||||
@@ -150,7 +150,7 @@ public class RLPSubCommand implements Runnable {
|
||||
|
||||
/**
|
||||
* Encodes the JSON input into an RLP data based on the {@link #type} then goes to {@link
|
||||
* #writeOutput(BytesValue)} this data to file or stdout
|
||||
* #writeOutput(Bytes)} this data to file or stdout
|
||||
*
|
||||
* @param jsonInput the JSON string data to encode
|
||||
*/
|
||||
@@ -180,7 +180,7 @@ public class RLPSubCommand implements Runnable {
|
||||
*
|
||||
* @param rlpEncodedOutput the RLP output to write to file or stdout
|
||||
*/
|
||||
private void writeOutput(final BytesValue rlpEncodedOutput) {
|
||||
private void writeOutput(final Bytes rlpEncodedOutput) {
|
||||
if (rlpTargetFile != null) {
|
||||
final Path targetPath = rlpTargetFile.toPath();
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@ package org.hyperledger.besu.controller;
|
||||
|
||||
import org.hyperledger.besu.crypto.InvalidSEC256K1PrivateKeyStoreException;
|
||||
import org.hyperledger.besu.crypto.SECP256K1;
|
||||
import org.hyperledger.besu.util.bytes.Bytes32;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -27,6 +26,7 @@ import java.nio.file.Path;
|
||||
import com.google.common.io.Resources;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.tuweni.bytes.Bytes32;
|
||||
|
||||
public class KeyPairUtil {
|
||||
private static final Logger LOG = LogManager.getLogger();
|
||||
|
||||
@@ -20,6 +20,7 @@ import org.hyperledger.besu.ethereum.api.query.LogsQuery;
|
||||
import org.hyperledger.besu.ethereum.chain.Blockchain;
|
||||
import org.hyperledger.besu.ethereum.core.LogTopic;
|
||||
import org.hyperledger.besu.ethereum.core.LogWithMetadata;
|
||||
import org.hyperledger.besu.ethereum.core.QuantityWrapper;
|
||||
import org.hyperledger.besu.ethereum.eth.sync.BlockBroadcaster;
|
||||
import org.hyperledger.besu.ethereum.eth.sync.state.SyncState;
|
||||
import org.hyperledger.besu.ethereum.eth.transactions.TransactionPool;
|
||||
@@ -28,11 +29,15 @@ import org.hyperledger.besu.plugin.data.BlockHeader;
|
||||
import org.hyperledger.besu.plugin.data.Hash;
|
||||
import org.hyperledger.besu.plugin.data.PropagatedBlockContext;
|
||||
import org.hyperledger.besu.plugin.data.Quantity;
|
||||
import org.hyperledger.besu.plugin.data.UnformattedData;
|
||||
import org.hyperledger.besu.plugin.services.BesuEvents;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import org.apache.tuweni.bytes.Bytes;
|
||||
import org.apache.tuweni.units.bigints.UInt256;
|
||||
|
||||
public class BesuEventsImpl implements BesuEvents {
|
||||
private Blockchain blockchain;
|
||||
private final BlockBroadcaster blockBroadcaster;
|
||||
@@ -105,7 +110,11 @@ public class BesuEventsImpl implements BesuEvents {
|
||||
final List<List<LogTopic>> besuTopics =
|
||||
topics.stream()
|
||||
.map(
|
||||
subList -> subList.stream().map(LogTopic::fromPlugin).collect(toUnmodifiableList()))
|
||||
subList ->
|
||||
subList.stream()
|
||||
.map(UnformattedData::getByteArray)
|
||||
.map(bytes -> LogTopic.wrap(Bytes.wrap(bytes)))
|
||||
.collect(toUnmodifiableList()))
|
||||
.collect(toUnmodifiableList());
|
||||
|
||||
final LogsQuery logsQuery = new LogsQuery(besuAddresses, besuTopics);
|
||||
@@ -125,7 +134,7 @@ public class BesuEventsImpl implements BesuEvents {
|
||||
|
||||
private static PropagatedBlockContext blockPropagatedContext(
|
||||
final Supplier<BlockHeader> blockHeaderSupplier,
|
||||
final Supplier<Quantity> totalDifficultySupplier) {
|
||||
final Supplier<UInt256> totalDifficultySupplier) {
|
||||
return new PropagatedBlockContext() {
|
||||
@Override
|
||||
public BlockHeader getBlockHeader() {
|
||||
@@ -134,7 +143,7 @@ public class BesuEventsImpl implements BesuEvents {
|
||||
|
||||
@Override
|
||||
public Quantity getTotalDifficulty() {
|
||||
return totalDifficultySupplier.get();
|
||||
return new QuantityWrapper(totalDifficultySupplier.get());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -56,7 +56,6 @@ import org.hyperledger.besu.plugin.services.storage.rocksdb.RocksDBMetricsFactor
|
||||
import org.hyperledger.besu.plugin.services.storage.rocksdb.configuration.RocksDBFactoryConfiguration;
|
||||
import org.hyperledger.besu.services.BesuConfigurationImpl;
|
||||
import org.hyperledger.besu.testutil.TestClock;
|
||||
import org.hyperledger.besu.util.uint.UInt256;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.net.InetAddress;
|
||||
@@ -81,6 +80,7 @@ import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.RequestBody;
|
||||
import okhttp3.Response;
|
||||
import org.apache.tuweni.units.bigints.UInt256;
|
||||
import org.awaitility.Awaitility;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
@@ -290,7 +290,7 @@ public final class RunnerTest {
|
||||
final int currentBlock =
|
||||
UInt256.fromHexString(
|
||||
new JsonObject(resp.body().string()).getString("result"))
|
||||
.toInt();
|
||||
.intValue();
|
||||
if (currentBlock < blockCount) {
|
||||
// if not yet at blockCount, we should get a sync result from eth_syncing
|
||||
final int syncResultCurrentBlock =
|
||||
@@ -298,7 +298,7 @@ public final class RunnerTest {
|
||||
new JsonObject(syncingResp.body().string())
|
||||
.getJsonObject("result")
|
||||
.getString("currentBlock"))
|
||||
.toInt();
|
||||
.intValue();
|
||||
assertThat(syncResultCurrentBlock).isLessThan(blockCount);
|
||||
}
|
||||
assertThat(currentBlock).isEqualTo(blockCount);
|
||||
|
||||
@@ -38,7 +38,6 @@ import org.hyperledger.besu.ethereum.eth.sync.SynchronizerConfiguration;
|
||||
import org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration;
|
||||
import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem;
|
||||
import org.hyperledger.besu.testutil.TestClock;
|
||||
import org.hyperledger.besu.util.bytes.BytesValue;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.math.BigInteger;
|
||||
@@ -51,6 +50,7 @@ import java.util.List;
|
||||
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.google.common.io.Resources;
|
||||
import org.apache.tuweni.bytes.Bytes;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
@@ -127,7 +127,7 @@ public abstract class JsonBlockImporterTest {
|
||||
// Check block 1
|
||||
Block block = blocks.get(0);
|
||||
if (isEthash) {
|
||||
assertThat(block.getHeader().getExtraData()).isEqualTo(BytesValue.EMPTY);
|
||||
assertThat(block.getHeader().internalGetExtraData()).isEqualTo(Bytes.EMPTY);
|
||||
assertThat(block.getHeader().getCoinbase()).isEqualTo(Address.ZERO);
|
||||
}
|
||||
assertThat(block.getBody().getTransactions().size()).isEqualTo(2);
|
||||
@@ -155,7 +155,8 @@ public abstract class JsonBlockImporterTest {
|
||||
// Check block 2
|
||||
block = blocks.get(1);
|
||||
if (isEthash) {
|
||||
assertThat(block.getHeader().getExtraData()).isEqualTo(BytesValue.fromHexString("0x1234"));
|
||||
assertThat(block.getHeader().internalGetExtraData())
|
||||
.isEqualTo(Bytes.fromHexString("0x1234"));
|
||||
assertThat(block.getHeader().getCoinbase()).isEqualTo(Address.fromHexString("0x02"));
|
||||
}
|
||||
assertThat(block.getBody().getTransactions().size()).isEqualTo(1);
|
||||
@@ -173,7 +174,8 @@ public abstract class JsonBlockImporterTest {
|
||||
// Check block 3
|
||||
block = blocks.get(2);
|
||||
if (isEthash) {
|
||||
assertThat(block.getHeader().getExtraData()).isEqualTo(BytesValue.fromHexString("0x3456"));
|
||||
assertThat(block.getHeader().internalGetExtraData())
|
||||
.isEqualTo(Bytes.fromHexString("0x3456"));
|
||||
assertThat(block.getHeader().getCoinbase())
|
||||
.isEqualTo(Address.fromHexString("f17f52151EbEF6C7334FAD080c5704D77216b732"));
|
||||
}
|
||||
@@ -182,7 +184,7 @@ public abstract class JsonBlockImporterTest {
|
||||
// Check block 4
|
||||
block = blocks.get(3);
|
||||
if (isEthash) {
|
||||
assertThat(block.getHeader().getExtraData()).isEqualTo(BytesValue.EMPTY);
|
||||
assertThat(block.getHeader().internalGetExtraData()).isEqualTo(Bytes.EMPTY);
|
||||
assertThat(block.getHeader().getCoinbase()).isEqualTo(Address.ZERO);
|
||||
}
|
||||
assertThat(block.getBody().getTransactions().size()).isEqualTo(1);
|
||||
@@ -218,7 +220,7 @@ public abstract class JsonBlockImporterTest {
|
||||
// Check block 1
|
||||
Block block = blocks.get(0);
|
||||
if (isEthash) {
|
||||
assertThat(block.getHeader().getExtraData()).isEqualTo(BytesValue.EMPTY);
|
||||
assertThat(block.getHeader().internalGetExtraData()).isEqualTo(Bytes.EMPTY);
|
||||
assertThat(block.getHeader().getCoinbase()).isEqualTo(Address.ZERO);
|
||||
}
|
||||
assertThat(block.getBody().getTransactions().size()).isEqualTo(2);
|
||||
@@ -246,7 +248,8 @@ public abstract class JsonBlockImporterTest {
|
||||
// Check block 2
|
||||
block = blocks.get(1);
|
||||
if (isEthash) {
|
||||
assertThat(block.getHeader().getExtraData()).isEqualTo(BytesValue.fromHexString("0x1234"));
|
||||
assertThat(block.getHeader().internalGetExtraData())
|
||||
.isEqualTo(Bytes.fromHexString("0x1234"));
|
||||
assertThat(block.getHeader().getCoinbase()).isEqualTo(Address.fromHexString("0x02"));
|
||||
}
|
||||
assertThat(block.getBody().getTransactions().size()).isEqualTo(1);
|
||||
@@ -264,7 +267,8 @@ public abstract class JsonBlockImporterTest {
|
||||
// Check block 3
|
||||
block = blocks.get(2);
|
||||
if (isEthash) {
|
||||
assertThat(block.getHeader().getExtraData()).isEqualTo(BytesValue.fromHexString("0x3456"));
|
||||
assertThat(block.getHeader().internalGetExtraData())
|
||||
.isEqualTo(Bytes.fromHexString("0x3456"));
|
||||
assertThat(block.getHeader().getCoinbase())
|
||||
.isEqualTo(Address.fromHexString("f17f52151EbEF6C7334FAD080c5704D77216b732"));
|
||||
}
|
||||
@@ -273,7 +277,7 @@ public abstract class JsonBlockImporterTest {
|
||||
// Check block 4
|
||||
block = blocks.get(3);
|
||||
if (isEthash) {
|
||||
assertThat(block.getHeader().getExtraData()).isEqualTo(BytesValue.EMPTY);
|
||||
assertThat(block.getHeader().internalGetExtraData()).isEqualTo(Bytes.EMPTY);
|
||||
assertThat(block.getHeader().getCoinbase()).isEqualTo(Address.ZERO);
|
||||
}
|
||||
assertThat(block.getBody().getTransactions().size()).isEqualTo(1);
|
||||
@@ -323,7 +327,7 @@ public abstract class JsonBlockImporterTest {
|
||||
// Check block 1
|
||||
assertThat(newBlock.getHeader().getParentHash()).isEqualTo(parentBlock.getHash());
|
||||
if (isEthash) {
|
||||
assertThat(newBlock.getHeader().getExtraData()).isEqualTo(BytesValue.EMPTY);
|
||||
assertThat(newBlock.getHeader().internalGetExtraData()).isEqualTo(Bytes.EMPTY);
|
||||
assertThat(newBlock.getHeader().getCoinbase()).isEqualTo(Address.ZERO);
|
||||
}
|
||||
assertThat(newBlock.getBody().getTransactions().size()).isEqualTo(1);
|
||||
@@ -375,7 +379,8 @@ public abstract class JsonBlockImporterTest {
|
||||
importer.importChain(jsonData);
|
||||
final Blockchain blockchain = controller.getProtocolContext().getBlockchain();
|
||||
final Block block = getBlockAt(blockchain, 1);
|
||||
assertThat(block.getHeader().getExtraData()).isEqualTo(BytesValue.fromHexString("0x0123"));
|
||||
assertThat(block.getHeader().internalGetExtraData())
|
||||
.isEqualTo(Bytes.fromHexString("0x0123"));
|
||||
assertThat(block.getHeader().getCoinbase())
|
||||
.isEqualTo(Address.fromHexString("627306090abaB3A6e1400e9345bC60c78a8BEf57"));
|
||||
} else {
|
||||
|
||||
@@ -30,7 +30,6 @@ import org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfigurati
|
||||
import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem;
|
||||
import org.hyperledger.besu.testutil.BlockTestUtil;
|
||||
import org.hyperledger.besu.testutil.TestClock;
|
||||
import org.hyperledger.besu.util.uint.UInt256;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.math.BigInteger;
|
||||
@@ -39,6 +38,7 @@ import java.nio.file.Path;
|
||||
import java.nio.file.StandardOpenOption;
|
||||
|
||||
import com.google.common.io.Resources;
|
||||
import org.apache.tuweni.units.bigints.UInt256;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
@@ -75,7 +75,7 @@ public final class RlpBlockImporterTest {
|
||||
rlpBlockImporter.importBlockchain(source, targetController);
|
||||
// Don't count the Genesis block
|
||||
assertThat(result.count).isEqualTo(999);
|
||||
assertThat(result.td).isEqualTo(UInt256.of(21991996248790L));
|
||||
assertThat(result.td).isEqualTo(UInt256.valueOf(21991996248790L));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -62,7 +62,6 @@ import org.hyperledger.besu.ethereum.worldstate.PrunerConfiguration;
|
||||
import org.hyperledger.besu.metrics.StandardMetricCategory;
|
||||
import org.hyperledger.besu.metrics.prometheus.MetricsConfiguration;
|
||||
import org.hyperledger.besu.nat.NatMethod;
|
||||
import org.hyperledger.besu.util.bytes.BytesValue;
|
||||
import org.hyperledger.besu.util.number.Fraction;
|
||||
import org.hyperledger.besu.util.number.Percentage;
|
||||
|
||||
@@ -87,6 +86,7 @@ import com.google.common.collect.Lists;
|
||||
import com.google.common.io.Resources;
|
||||
import io.vertx.core.json.JsonObject;
|
||||
import org.apache.commons.text.StringEscapeUtils;
|
||||
import org.apache.tuweni.bytes.Bytes;
|
||||
import org.apache.tuweni.toml.Toml;
|
||||
import org.apache.tuweni.toml.TomlParseResult;
|
||||
import org.junit.Rule;
|
||||
@@ -192,7 +192,7 @@ public class BesuCommandTest extends CommandTestAbstract {
|
||||
assertThat(commandErrorOutput.toString()).isEmpty();
|
||||
assertThat(miningArg.getValue().getCoinbase()).isEqualTo(Optional.empty());
|
||||
assertThat(miningArg.getValue().getMinTransactionGasPrice()).isEqualTo(Wei.of(1000));
|
||||
assertThat(miningArg.getValue().getExtraData()).isEqualTo(BytesValue.EMPTY);
|
||||
assertThat(miningArg.getValue().getExtraData()).isEqualTo(Bytes.EMPTY);
|
||||
assertThat(ethNetworkArg.getValue().getNetworkId()).isEqualTo(1);
|
||||
assertThat(ethNetworkArg.getValue().getBootNodes()).isEqualTo(MAINNET_BOOTSTRAP_NODES);
|
||||
}
|
||||
@@ -1159,23 +1159,23 @@ public class BesuCommandTest extends CommandTestAbstract {
|
||||
|
||||
@Test
|
||||
public void bannedNodeIdsOptionMustBeUsed() {
|
||||
final BytesValue[] nodes = {
|
||||
BytesValue.fromHexString(
|
||||
final Bytes[] nodes = {
|
||||
Bytes.fromHexString(
|
||||
"6f8a80d14311c39f35f516fa664deaaaa13e85b2f7493f37f6144d86991ec012937307647bd3b9a82abe2974e1407241d54947bbb39763a4cac9f77166ad92a0"),
|
||||
BytesValue.fromHexString(
|
||||
Bytes.fromHexString(
|
||||
"7f8a80d14311c39f35f516fa664deaaaa13e85b2f7493f37f6144d86991ec012937307647bd3b9a82abe2974e1407241d54947bbb39763a4cac9f77166ad92a0"),
|
||||
BytesValue.fromHexString(
|
||||
Bytes.fromHexString(
|
||||
"0x8f8a80d14311c39f35f516fa664deaaaa13e85b2f7493f37f6144d86991ec012937307647bd3b9a82abe2974e1407241d54947bbb39763a4cac9f77166ad92a0")
|
||||
};
|
||||
|
||||
final String nodeIdsArg =
|
||||
Arrays.stream(nodes).map(BytesValue::toUnprefixedString).collect(Collectors.joining(","));
|
||||
Arrays.stream(nodes).map(Bytes::toShortHexString).collect(Collectors.joining(","));
|
||||
parseCommand("--banned-node-ids", nodeIdsArg);
|
||||
|
||||
verify(mockRunnerBuilder).bannedNodeIds(bytesValueCollectionCollector.capture());
|
||||
verify(mockRunnerBuilder).bannedNodeIds(bytesCollectionCollector.capture());
|
||||
verify(mockRunnerBuilder).build();
|
||||
|
||||
assertThat(bytesValueCollectionCollector.getValue().toArray()).isEqualTo(nodes);
|
||||
assertThat(bytesCollectionCollector.getValue().toArray()).isEqualTo(nodes);
|
||||
|
||||
assertThat(commandOutput.toString()).isEmpty();
|
||||
assertThat(commandErrorOutput.toString()).isEmpty();
|
||||
@@ -2354,8 +2354,7 @@ public class BesuCommandTest extends CommandTestAbstract {
|
||||
assertThat(commandErrorOutput.toString()).isEmpty();
|
||||
assertThat(miningArg.getValue().getCoinbase()).isEqualTo(Optional.of(requestedCoinbase));
|
||||
assertThat(miningArg.getValue().getMinTransactionGasPrice()).isEqualTo(Wei.of(15));
|
||||
assertThat(miningArg.getValue().getExtraData())
|
||||
.isEqualTo(BytesValue.fromHexString(extraDataString));
|
||||
assertThat(miningArg.getValue().getExtraData()).isEqualTo(Bytes.fromHexString(extraDataString));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -59,7 +59,6 @@ import org.hyperledger.besu.plugin.services.storage.KeyValueStorageFactory;
|
||||
import org.hyperledger.besu.plugin.services.storage.PrivacyKeyValueStorageFactory;
|
||||
import org.hyperledger.besu.services.BesuPluginContextImpl;
|
||||
import org.hyperledger.besu.services.StorageServiceImpl;
|
||||
import org.hyperledger.besu.util.bytes.BytesValue;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
@@ -80,6 +79,7 @@ import io.vertx.core.Vertx;
|
||||
import io.vertx.core.VertxOptions;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.tuweni.bytes.Bytes;
|
||||
import org.awaitility.Awaitility;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
@@ -132,7 +132,7 @@ public abstract class CommandTestAbstract {
|
||||
@Mock protected Logger mockLogger;
|
||||
@Mock protected BesuPluginContextImpl mockBesuPluginContext;
|
||||
|
||||
@Captor protected ArgumentCaptor<Collection<BytesValue>> bytesValueCollectionCollector;
|
||||
@Captor protected ArgumentCaptor<Collection<Bytes>> bytesCollectionCollector;
|
||||
@Captor protected ArgumentCaptor<Path> pathArgumentCaptor;
|
||||
@Captor protected ArgumentCaptor<File> fileArgumentCaptor;
|
||||
@Captor protected ArgumentCaptor<String> stringArgumentCaptor;
|
||||
|
||||
@@ -17,11 +17,10 @@ package org.hyperledger.besu.cli.options;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
|
||||
import org.hyperledger.besu.util.uint.UInt256;
|
||||
|
||||
import java.math.BigInteger;
|
||||
|
||||
import com.google.common.collect.Range;
|
||||
import org.apache.tuweni.units.bigints.UInt256;
|
||||
import org.junit.Test;
|
||||
|
||||
public class OptionParserTest {
|
||||
@@ -70,7 +69,7 @@ public class OptionParserTest {
|
||||
|
||||
@Test
|
||||
public void format_uint256() {
|
||||
final UInt256 input = UInt256.of(new BigInteger("123456789", 10));
|
||||
final UInt256 input = UInt256.valueOf(new BigInteger("123456789", 10));
|
||||
final String expected = "123456789";
|
||||
assertThat(OptionParser.format(input)).isEqualTo(expected);
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ public class SynchronizerOptionsTest
|
||||
.downloaderChangeTargetThresholdByHeight(
|
||||
SynchronizerConfiguration.DEFAULT_DOWNLOADER_CHANGE_TARGET_THRESHOLD_BY_HEIGHT + 2)
|
||||
.downloaderChangeTargetThresholdByTd(
|
||||
SynchronizerConfiguration.DEFAULT_DOWNLOADER_CHANGE_TARGET_THRESHOLD_BY_TD.plus(2L))
|
||||
SynchronizerConfiguration.DEFAULT_DOWNLOADER_CHANGE_TARGET_THRESHOLD_BY_TD.add(2L))
|
||||
.downloaderHeadersRequestSize(
|
||||
SynchronizerConfiguration.DEFAULT_DOWNLOADER_HEADER_REQUEST_SIZE + 2)
|
||||
.downloaderCheckpointTimeoutsPermitted(
|
||||
|
||||
@@ -55,8 +55,8 @@ import org.hyperledger.besu.plugin.data.SyncStatus;
|
||||
import org.hyperledger.besu.plugin.data.Transaction;
|
||||
import org.hyperledger.besu.services.kvstore.InMemoryKeyValueStorage;
|
||||
import org.hyperledger.besu.testutil.TestClock;
|
||||
import org.hyperledger.besu.util.uint.UInt256;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@@ -64,6 +64,7 @@ import java.util.Optional;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.apache.tuweni.units.bigints.UInt256;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -182,11 +183,11 @@ public class BesuEventsImplTest {
|
||||
serviceImpl.addBlockPropagatedListener(result::set);
|
||||
final Block block = generateBlock();
|
||||
assertThat(result.get()).isNull();
|
||||
blockBroadcaster.propagate(block, UInt256.of(1));
|
||||
blockBroadcaster.propagate(block, UInt256.valueOf(1));
|
||||
|
||||
assertThat(result.get()).isNotNull();
|
||||
assertThat(result.get().getBlockHeader()).isEqualTo(block.getHeader());
|
||||
assertThat(result.get().getTotalDifficulty()).isEqualTo(UInt256.of(1));
|
||||
assertThat(result.get().getTotalDifficulty().getValue()).isEqualTo(BigInteger.ONE);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -196,21 +197,21 @@ public class BesuEventsImplTest {
|
||||
|
||||
assertThat(result.get()).isNull();
|
||||
final Block block = generateBlock();
|
||||
blockBroadcaster.propagate(block, UInt256.of(2));
|
||||
blockBroadcaster.propagate(block, UInt256.valueOf(2));
|
||||
|
||||
assertThat(result.get()).isNotNull();
|
||||
assertThat(result.get().getBlockHeader()).isEqualTo(block.getHeader());
|
||||
assertThat(result.get().getTotalDifficulty()).isEqualTo(UInt256.of(2));
|
||||
assertThat(result.get().getTotalDifficulty().getValue()).isEqualTo(BigInteger.valueOf(2L));
|
||||
serviceImpl.removeBlockPropagatedListener(id);
|
||||
result.set(null);
|
||||
|
||||
blockBroadcaster.propagate(generateBlock(), UInt256.of(1));
|
||||
blockBroadcaster.propagate(generateBlock(), UInt256.valueOf(1));
|
||||
assertThat(result.get()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void propagationWithoutSubscriptionsCompletes() {
|
||||
blockBroadcaster.propagate(generateBlock(), UInt256.of(1));
|
||||
blockBroadcaster.propagate(generateBlock(), UInt256.valueOf(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -122,6 +122,7 @@ allprojects {
|
||||
mavenCentral()
|
||||
mavenLocal()
|
||||
maven { url "https://consensys.bintray.com/pegasys-repo" }
|
||||
maven { url "https://repository.apache.org/content/repositories/snapshots/" }
|
||||
}
|
||||
|
||||
dependencies { errorprone("com.google.errorprone:error_prone_core") }
|
||||
|
||||
@@ -44,6 +44,8 @@ dependencies {
|
||||
|
||||
implementation 'io.vertx:vertx-core'
|
||||
implementation 'com.google.guava:guava'
|
||||
implementation 'org.apache.tuweni:tuweni-bytes'
|
||||
implementation 'org.apache.tuweni:tuweni-units'
|
||||
|
||||
testImplementation project(path: ':ethereum:core', configuration: 'testSupportArtifacts')
|
||||
testImplementation project(path: ':consensus:common', configuration: 'testArtifacts')
|
||||
|
||||
@@ -20,10 +20,11 @@ import org.hyperledger.besu.ethereum.core.BlockHeader;
|
||||
import org.hyperledger.besu.ethereum.core.Hash;
|
||||
import org.hyperledger.besu.ethereum.core.Util;
|
||||
import org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput;
|
||||
import org.hyperledger.besu.util.bytes.BytesValue;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import org.apache.tuweni.bytes.Bytes;
|
||||
|
||||
public class CliqueBlockHashing {
|
||||
/**
|
||||
* Constructs a hash of the block header, suitable for use when creating the proposer seal. The
|
||||
@@ -36,7 +37,7 @@ public class CliqueBlockHashing {
|
||||
*/
|
||||
public static Hash calculateDataHashForProposerSeal(
|
||||
final BlockHeader header, final CliqueExtraData cliqueExtraData) {
|
||||
final BytesValue headerRlp = serializeHeaderWithoutProposerSeal(header, cliqueExtraData);
|
||||
final Bytes headerRlp = serializeHeaderWithoutProposerSeal(header, cliqueExtraData);
|
||||
return Hash.hash(headerRlp); // Proposer hash is the hash of the RLP
|
||||
}
|
||||
|
||||
@@ -60,37 +61,36 @@ public class CliqueBlockHashing {
|
||||
return Util.signatureToAddress(cliqueExtraData.getProposerSeal().get(), proposerHash);
|
||||
}
|
||||
|
||||
private static BytesValue serializeHeaderWithoutProposerSeal(
|
||||
private static Bytes serializeHeaderWithoutProposerSeal(
|
||||
final BlockHeader header, final CliqueExtraData cliqueExtraData) {
|
||||
return serializeHeader(header, () -> encodeExtraDataWithoutProposerSeal(cliqueExtraData));
|
||||
}
|
||||
|
||||
private static BytesValue encodeExtraDataWithoutProposerSeal(
|
||||
final CliqueExtraData cliqueExtraData) {
|
||||
final BytesValue extraDataBytes = cliqueExtraData.encode();
|
||||
private static Bytes encodeExtraDataWithoutProposerSeal(final CliqueExtraData cliqueExtraData) {
|
||||
final Bytes extraDataBytes = cliqueExtraData.encode();
|
||||
// Always trim off final 65 bytes (which maybe zeros)
|
||||
return extraDataBytes.slice(0, extraDataBytes.size() - Signature.BYTES_REQUIRED);
|
||||
}
|
||||
|
||||
private static BytesValue serializeHeader(
|
||||
final BlockHeader header, final Supplier<BytesValue> extraDataSerializer) {
|
||||
private static Bytes serializeHeader(
|
||||
final BlockHeader header, final Supplier<Bytes> extraDataSerializer) {
|
||||
final BytesValueRLPOutput out = new BytesValueRLPOutput();
|
||||
out.startList();
|
||||
|
||||
out.writeBytesValue(header.getParentHash());
|
||||
out.writeBytesValue(header.getOmmersHash());
|
||||
out.writeBytesValue(header.getCoinbase());
|
||||
out.writeBytesValue(header.getStateRoot());
|
||||
out.writeBytesValue(header.getTransactionsRoot());
|
||||
out.writeBytesValue(header.getReceiptsRoot());
|
||||
out.writeBytesValue(header.getLogsBloom().getBytes());
|
||||
out.writeUInt256Scalar(header.getDifficulty());
|
||||
out.writeBytes(header.getParentHash());
|
||||
out.writeBytes(header.getOmmersHash());
|
||||
out.writeBytes(header.getCoinbase());
|
||||
out.writeBytes(header.getStateRoot());
|
||||
out.writeBytes(header.getTransactionsRoot());
|
||||
out.writeBytes(header.getReceiptsRoot());
|
||||
out.writeBytes(header.getLogsBloom().getBytes());
|
||||
out.writeBytes(header.internalGetDifficulty().toMinimalBytes());
|
||||
out.writeLongScalar(header.getNumber());
|
||||
out.writeLongScalar(header.getGasLimit());
|
||||
out.writeLongScalar(header.getGasUsed());
|
||||
out.writeLongScalar(header.getTimestamp());
|
||||
out.writeBytesValue(extraDataSerializer.get());
|
||||
out.writeBytesValue(header.getMixHash());
|
||||
out.writeBytes(extraDataSerializer.get());
|
||||
out.writeBytes(header.getMixHash());
|
||||
out.writeLong(header.getNonce());
|
||||
out.endList();
|
||||
return out.encoded();
|
||||
|
||||
@@ -20,17 +20,16 @@ import org.hyperledger.besu.consensus.common.VoteType;
|
||||
import org.hyperledger.besu.ethereum.core.Address;
|
||||
import org.hyperledger.besu.ethereum.core.BlockHeader;
|
||||
import org.hyperledger.besu.ethereum.core.BlockHeaderBuilder;
|
||||
import org.hyperledger.besu.util.bytes.BytesValue;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Optional;
|
||||
|
||||
import com.google.common.collect.ImmutableBiMap;
|
||||
import org.apache.tuweni.bytes.Bytes;
|
||||
|
||||
public class CliqueBlockInterface implements BlockInterface {
|
||||
|
||||
public static final Address NO_VOTE_SUBJECT =
|
||||
Address.wrap(BytesValue.wrap(new byte[Address.SIZE]));
|
||||
public static final Address NO_VOTE_SUBJECT = Address.wrap(Bytes.wrap(new byte[Address.SIZE]));
|
||||
|
||||
public static final long ADD_NONCE = 0xFFFFFFFFFFFFFFFFL;
|
||||
public static final long DROP_NONCE = 0x0L;
|
||||
|
||||
@@ -21,8 +21,6 @@ import org.hyperledger.besu.crypto.SECP256K1.Signature;
|
||||
import org.hyperledger.besu.ethereum.core.Address;
|
||||
import org.hyperledger.besu.ethereum.core.BlockHeader;
|
||||
import org.hyperledger.besu.ethereum.core.ParsedExtraData;
|
||||
import org.hyperledger.besu.util.bytes.BytesValue;
|
||||
import org.hyperledger.besu.util.bytes.BytesValues;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
@@ -32,6 +30,7 @@ import com.google.common.base.Suppliers;
|
||||
import com.google.common.collect.Lists;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.tuweni.bytes.Bytes;
|
||||
|
||||
/**
|
||||
* Represents the data structure stored in the extraData field of the BlockHeader used when
|
||||
@@ -41,13 +40,13 @@ public class CliqueExtraData implements ParsedExtraData {
|
||||
private static final Logger LOG = LogManager.getLogger();
|
||||
public static final int EXTRA_VANITY_LENGTH = 32;
|
||||
|
||||
private final BytesValue vanityData;
|
||||
private final Bytes vanityData;
|
||||
private final List<Address> validators;
|
||||
private final Optional<Signature> proposerSeal;
|
||||
private final Supplier<Address> proposerAddress;
|
||||
|
||||
public CliqueExtraData(
|
||||
final BytesValue vanityData,
|
||||
final Bytes vanityData,
|
||||
final Signature proposerSeal,
|
||||
final List<Address> validators,
|
||||
final BlockHeader header) {
|
||||
@@ -64,8 +63,8 @@ public class CliqueExtraData implements ParsedExtraData {
|
||||
Suppliers.memoize(() -> CliqueBlockHashing.recoverProposerAddress(header, this));
|
||||
}
|
||||
|
||||
public static BytesValue createWithoutProposerSeal(
|
||||
final BytesValue vanityData, final List<Address> validators) {
|
||||
public static Bytes createWithoutProposerSeal(
|
||||
final Bytes vanityData, final List<Address> validators) {
|
||||
return CliqueExtraData.encodeUnsealed(vanityData, validators);
|
||||
}
|
||||
|
||||
@@ -81,19 +80,18 @@ public class CliqueExtraData implements ParsedExtraData {
|
||||
}
|
||||
|
||||
static CliqueExtraData decodeRaw(final BlockHeader header) {
|
||||
final BytesValue input = header.getExtraData();
|
||||
final Bytes input = header.internalGetExtraData();
|
||||
if (input.size() < EXTRA_VANITY_LENGTH + Signature.BYTES_REQUIRED) {
|
||||
throw new IllegalArgumentException(
|
||||
"Invalid BytesValue supplied - too short to produce a valid Clique Extra Data object.");
|
||||
"Invalid Bytes supplied - too short to produce a valid Clique Extra Data object.");
|
||||
}
|
||||
|
||||
final int validatorByteCount = input.size() - EXTRA_VANITY_LENGTH - Signature.BYTES_REQUIRED;
|
||||
if ((validatorByteCount % Address.SIZE) != 0) {
|
||||
throw new IllegalArgumentException(
|
||||
"BytesValue is of invalid size - i.e. contains unused bytes.");
|
||||
throw new IllegalArgumentException("Bytes is of invalid size - i.e. contains unused bytes.");
|
||||
}
|
||||
|
||||
final BytesValue vanityData = input.slice(0, EXTRA_VANITY_LENGTH);
|
||||
final Bytes vanityData = input.slice(0, EXTRA_VANITY_LENGTH);
|
||||
final List<Address> validators =
|
||||
extractValidators(input.slice(EXTRA_VANITY_LENGTH, validatorByteCount));
|
||||
|
||||
@@ -107,11 +105,11 @@ public class CliqueExtraData implements ParsedExtraData {
|
||||
return proposerAddress.get();
|
||||
}
|
||||
|
||||
private static Signature parseProposerSeal(final BytesValue proposerSealRaw) {
|
||||
private static Signature parseProposerSeal(final Bytes proposerSealRaw) {
|
||||
return proposerSealRaw.isZero() ? null : Signature.decode(proposerSealRaw);
|
||||
}
|
||||
|
||||
private static List<Address> extractValidators(final BytesValue validatorsRaw) {
|
||||
private static List<Address> extractValidators(final Bytes validatorsRaw) {
|
||||
final List<Address> result = Lists.newArrayList();
|
||||
final int countValidators = validatorsRaw.size() / Address.SIZE;
|
||||
for (int i = 0; i < countValidators; i++) {
|
||||
@@ -121,29 +119,28 @@ public class CliqueExtraData implements ParsedExtraData {
|
||||
return result;
|
||||
}
|
||||
|
||||
public BytesValue encode() {
|
||||
public Bytes encode() {
|
||||
return encode(vanityData, validators, proposerSeal);
|
||||
}
|
||||
|
||||
public static BytesValue encodeUnsealed(
|
||||
final BytesValue vanityData, final List<Address> validators) {
|
||||
public static Bytes encodeUnsealed(final Bytes vanityData, final List<Address> validators) {
|
||||
return encode(vanityData, validators, Optional.empty());
|
||||
}
|
||||
|
||||
private static BytesValue encode(
|
||||
final BytesValue vanityData,
|
||||
private static Bytes encode(
|
||||
final Bytes vanityData,
|
||||
final List<Address> validators,
|
||||
final Optional<Signature> proposerSeal) {
|
||||
final BytesValue validatorData = BytesValues.concatenate(validators.toArray(new Address[0]));
|
||||
return BytesValues.concatenate(
|
||||
final Bytes validatorData = Bytes.concatenate(validators.toArray(new Bytes[0]));
|
||||
return Bytes.concatenate(
|
||||
vanityData,
|
||||
validatorData,
|
||||
proposerSeal
|
||||
.map(Signature::encodedBytes)
|
||||
.orElse(BytesValue.wrap(new byte[Signature.BYTES_REQUIRED])));
|
||||
.orElse(Bytes.wrap(new byte[Signature.BYTES_REQUIRED])));
|
||||
}
|
||||
|
||||
public BytesValue getVanityData() {
|
||||
public Bytes getVanityData() {
|
||||
return vanityData;
|
||||
}
|
||||
|
||||
@@ -156,7 +153,7 @@ public class CliqueExtraData implements ParsedExtraData {
|
||||
}
|
||||
|
||||
public static String createGenesisExtraDataString(final List<Address> validators) {
|
||||
return CliqueExtraData.createWithoutProposerSeal(BytesValue.wrap(new byte[32]), validators)
|
||||
return CliqueExtraData.createWithoutProposerSeal(Bytes.wrap(new byte[32]), validators)
|
||||
.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,6 @@ import org.hyperledger.besu.ethereum.core.Util;
|
||||
import org.hyperledger.besu.ethereum.eth.transactions.PendingTransactions;
|
||||
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
|
||||
import org.hyperledger.besu.util.Subscribers;
|
||||
import org.hyperledger.besu.util.bytes.BytesValue;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
@@ -40,6 +39,7 @@ import java.util.function.Function;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.collect.Lists;
|
||||
import org.apache.tuweni.bytes.Bytes;
|
||||
|
||||
public class CliqueMinerExecutor extends AbstractMinerExecutor<CliqueContext, CliqueBlockMiner> {
|
||||
|
||||
@@ -103,10 +103,10 @@ public class CliqueMinerExecutor extends AbstractMinerExecutor<CliqueContext, Cl
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
BytesValue calculateExtraData(final BlockHeader parentHeader) {
|
||||
Bytes calculateExtraData(final BlockHeader parentHeader) {
|
||||
final List<Address> validators = Lists.newArrayList();
|
||||
|
||||
final BytesValue vanityDataToInsert =
|
||||
final Bytes vanityDataToInsert =
|
||||
ConsensusHelpers.zeroLeftPad(extraData, CliqueExtraData.EXTRA_VANITY_LENGTH);
|
||||
// Building ON TOP of canonical head, if the next block is epoch, include validators.
|
||||
if (epochManager.isEpochBlock(parentHeader.getNumber() + 1)) {
|
||||
|
||||
@@ -38,8 +38,7 @@ public class CliqueDifficultyValidationRule
|
||||
new CliqueDifficultyCalculator(actualBlockCreator);
|
||||
final BigInteger expectedDifficulty = diffCalculator.nextDifficulty(0, parent, protocolContext);
|
||||
|
||||
final BigInteger actualDifficulty =
|
||||
new BigInteger(1, header.getDifficulty().getBytes().extractArray());
|
||||
final BigInteger actualDifficulty = header.internalGetDifficulty().toBigInteger();
|
||||
|
||||
return expectedDifficulty.equals(actualDifficulty);
|
||||
}
|
||||
|
||||
@@ -21,12 +21,12 @@ import org.hyperledger.besu.ethereum.core.BlockHeader;
|
||||
import org.hyperledger.besu.ethereum.core.BlockHeaderBuilder;
|
||||
import org.hyperledger.besu.ethereum.core.Hash;
|
||||
import org.hyperledger.besu.ethereum.core.LogsBloomFilter;
|
||||
import org.hyperledger.besu.util.bytes.BytesValue;
|
||||
import org.hyperledger.besu.util.uint.UInt256;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.tuweni.bytes.Bytes;
|
||||
import org.apache.tuweni.units.bigints.UInt256;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -82,9 +82,9 @@ public class CliqueBlockHashingTest {
|
||||
// The following text was a dump from the geth console of the 30_000 block on Rinkeby.
|
||||
// eth.getBlock(30000)
|
||||
final BlockHeaderBuilder builder = new BlockHeaderBuilder();
|
||||
builder.difficulty(UInt256.of(2));
|
||||
builder.difficulty(UInt256.valueOf(2));
|
||||
builder.extraData(
|
||||
BytesValue.fromHexString(
|
||||
Bytes.fromHexString(
|
||||
"0xd783010600846765746887676f312e372e33856c696e7578000000000000000042eb768f2244c8811c63729a21a3569731535f067ffc57839b00206d1ad20c69a1981b489f772031b279182d99e65703f0076e4812653aab85fca0f0c5bc40d0535af16266714ccb26fc49448c10bdf2969411514707d7442956b3397b09a980f4bea9347f70eea52183326247a0239b6d01fa0b07afc44e8a05463301"));
|
||||
builder.gasLimit(4712388);
|
||||
builder.gasUsed(0);
|
||||
@@ -117,9 +117,9 @@ public class CliqueBlockHashingTest {
|
||||
private BlockHeader createGenesisBlock() {
|
||||
// The following was taken from the Rinkeby genesis file
|
||||
final BlockHeaderBuilder builder = new BlockHeaderBuilder();
|
||||
builder.difficulty(UInt256.of(1));
|
||||
builder.difficulty(UInt256.valueOf(1));
|
||||
builder.extraData(
|
||||
BytesValue.fromHexString(
|
||||
Bytes.fromHexString(
|
||||
"0x52657370656374206d7920617574686f7269746168207e452e436172746d616e42eb768f2244c8811c63729a21a3569731535f067ffc57839b00206d1ad20c69a1981b489f772031b279182d99e65703f0076e4812653aab85fca0f00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"));
|
||||
builder.gasLimit(4700000);
|
||||
builder.gasUsed(0);
|
||||
|
||||
@@ -24,7 +24,6 @@ import org.hyperledger.besu.ethereum.core.AddressHelpers;
|
||||
import org.hyperledger.besu.ethereum.core.BlockHeader;
|
||||
import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture;
|
||||
import org.hyperledger.besu.ethereum.core.Util;
|
||||
import org.hyperledger.besu.util.bytes.BytesValue;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.util.Arrays;
|
||||
@@ -32,6 +31,7 @@ import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import org.apache.tuweni.bytes.Bytes;
|
||||
import org.bouncycastle.util.encoders.Hex;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -43,13 +43,13 @@ public class CliqueExtraDataTest {
|
||||
final List<Address> validators =
|
||||
Arrays.asList(
|
||||
AddressHelpers.ofValue(1), AddressHelpers.ofValue(2), AddressHelpers.ofValue(3));
|
||||
final BytesValue vanityData = BytesValue.fromHexString("11223344", 32);
|
||||
final Bytes vanityData = Bytes.fromHexString("11223344", 32);
|
||||
|
||||
final CliqueExtraData extraData =
|
||||
new CliqueExtraData(
|
||||
vanityData, proposerSeal, validators, new BlockHeaderTestFixture().buildHeader());
|
||||
|
||||
final BytesValue serialisedData = extraData.encode();
|
||||
final Bytes serialisedData = extraData.encode();
|
||||
|
||||
final CliqueExtraData decodedExtraData =
|
||||
CliqueExtraData.decodeRaw(createHeaderWithExtraData(serialisedData));
|
||||
@@ -66,7 +66,7 @@ public class CliqueExtraDataTest {
|
||||
Hex.decode(
|
||||
"52657370656374206d7920617574686f7269746168207e452e436172746d616e42eb768f2244c8811c63729a21a3569731535f067ffc57839b00206d1ad20c69a1981b489f772031b279182d99e65703f0076e4812653aab85fca0f00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000");
|
||||
|
||||
final BytesValue bufferToInject = BytesValue.wrap(genesisBlockExtraData);
|
||||
final Bytes bufferToInject = Bytes.wrap(genesisBlockExtraData);
|
||||
|
||||
final CliqueExtraData extraData =
|
||||
CliqueExtraData.decodeRaw(
|
||||
@@ -81,20 +81,19 @@ public class CliqueExtraDataTest {
|
||||
|
||||
@Test
|
||||
public void insufficientDataResultsInAnIllegalArgumentException() {
|
||||
final BytesValue illegalData =
|
||||
BytesValue.wrap(
|
||||
new byte[Signature.BYTES_REQUIRED + CliqueExtraData.EXTRA_VANITY_LENGTH - 1]);
|
||||
final Bytes illegalData =
|
||||
Bytes.wrap(new byte[Signature.BYTES_REQUIRED + CliqueExtraData.EXTRA_VANITY_LENGTH - 1]);
|
||||
|
||||
assertThatThrownBy(() -> CliqueExtraData.decodeRaw(createHeaderWithExtraData(illegalData)))
|
||||
.isInstanceOf(IllegalArgumentException.class)
|
||||
.hasMessage(
|
||||
"Invalid BytesValue supplied - too short to produce a valid Clique Extra Data object.");
|
||||
"Invalid Bytes supplied - too short to produce a valid Clique Extra Data object.");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sufficientlyLargeButIllegallySizedInputThrowsException() {
|
||||
final BytesValue illegalData =
|
||||
BytesValue.wrap(
|
||||
final Bytes illegalData =
|
||||
Bytes.wrap(
|
||||
new byte
|
||||
[Signature.BYTES_REQUIRED
|
||||
+ CliqueExtraData.EXTRA_VANITY_LENGTH
|
||||
@@ -103,7 +102,7 @@ public class CliqueExtraDataTest {
|
||||
|
||||
assertThatThrownBy(() -> CliqueExtraData.decodeRaw(createHeaderWithExtraData(illegalData)))
|
||||
.isInstanceOf(IllegalArgumentException.class)
|
||||
.hasMessage("BytesValue is of invalid size - i.e. contains unused bytes.");
|
||||
.hasMessage("Bytes is of invalid size - i.e. contains unused bytes.");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -122,12 +121,12 @@ public class CliqueExtraDataTest {
|
||||
final String hexOutput = CliqueExtraData.createGenesisExtraDataString(addresses);
|
||||
|
||||
final CliqueExtraData extraData =
|
||||
CliqueExtraData.decodeRaw(createHeaderWithExtraData(BytesValue.fromHexString(hexOutput)));
|
||||
CliqueExtraData.decodeRaw(createHeaderWithExtraData(Bytes.fromHexString(hexOutput)));
|
||||
|
||||
assertThat(extraData.getValidators()).containsExactly(addresses.toArray(new Address[0]));
|
||||
}
|
||||
|
||||
private BlockHeader createHeaderWithExtraData(final BytesValue illegalData) {
|
||||
private BlockHeader createHeaderWithExtraData(final Bytes illegalData) {
|
||||
return new BlockHeaderTestFixture()
|
||||
.blockHeaderFunctions(new CliqueBlockHeaderFunctions())
|
||||
.extraData(illegalData)
|
||||
|
||||
@@ -21,10 +21,11 @@ import org.hyperledger.besu.ethereum.core.Address;
|
||||
import org.hyperledger.besu.ethereum.core.BlockHeader;
|
||||
import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture;
|
||||
import org.hyperledger.besu.ethereum.core.Hash;
|
||||
import org.hyperledger.besu.util.bytes.BytesValue;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.tuweni.bytes.Bytes;
|
||||
|
||||
public class TestHelpers {
|
||||
|
||||
public static BlockHeader createCliqueSignedBlockHeader(
|
||||
@@ -35,7 +36,7 @@ public class TestHelpers {
|
||||
final BlockHeader unsealedHeader =
|
||||
blockHeaderBuilder
|
||||
.blockHeaderFunctions(new CliqueBlockHeaderFunctions())
|
||||
.extraData(CliqueExtraData.encodeUnsealed(BytesValue.wrap(new byte[32]), validators))
|
||||
.extraData(CliqueExtraData.encodeUnsealed(Bytes.wrap(new byte[32]), validators))
|
||||
.buildHeader();
|
||||
final CliqueExtraData unsignedExtraData = CliqueExtraData.decodeRaw(unsealedHeader);
|
||||
|
||||
@@ -44,7 +45,7 @@ public class TestHelpers {
|
||||
|
||||
final Signature proposerSignature = SECP256K1.sign(signingHash, signer);
|
||||
|
||||
final BytesValue signedExtraData =
|
||||
final Bytes signedExtraData =
|
||||
new CliqueExtraData(
|
||||
unsignedExtraData.getVanityData(),
|
||||
proposerSignature,
|
||||
|
||||
@@ -50,11 +50,11 @@ import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive;
|
||||
import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem;
|
||||
import org.hyperledger.besu.plugin.services.MetricsSystem;
|
||||
import org.hyperledger.besu.testutil.TestClock;
|
||||
import org.hyperledger.besu.util.bytes.BytesValue;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import org.apache.tuweni.bytes.Bytes;
|
||||
import org.assertj.core.api.Java6Assertions;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -111,8 +111,8 @@ public class CliqueBlockCreatorTest {
|
||||
@Test
|
||||
public void proposerAddressCanBeExtractFromAConstructedBlock() {
|
||||
|
||||
final BytesValue extraData =
|
||||
CliqueExtraData.createWithoutProposerSeal(BytesValue.wrap(new byte[32]), validatorList);
|
||||
final Bytes extraData =
|
||||
CliqueExtraData.createWithoutProposerSeal(Bytes.wrap(new byte[32]), validatorList);
|
||||
|
||||
final Address coinbase = AddressHelpers.ofValue(1);
|
||||
final CliqueBlockCreator blockCreator =
|
||||
@@ -140,8 +140,8 @@ public class CliqueBlockCreatorTest {
|
||||
|
||||
@Test
|
||||
public void insertsValidVoteIntoConstructedBlock() {
|
||||
final BytesValue extraData =
|
||||
CliqueExtraData.createWithoutProposerSeal(BytesValue.wrap(new byte[32]), validatorList);
|
||||
final Bytes extraData =
|
||||
CliqueExtraData.createWithoutProposerSeal(Bytes.wrap(new byte[32]), validatorList);
|
||||
final Address a1 = Address.fromHexString("5");
|
||||
voteProposer.auth(a1);
|
||||
final Address coinbase = AddressHelpers.ofValue(1);
|
||||
@@ -170,8 +170,8 @@ public class CliqueBlockCreatorTest {
|
||||
|
||||
@Test
|
||||
public void insertsNoVoteWhenAuthInValidators() {
|
||||
final BytesValue extraData =
|
||||
CliqueExtraData.createWithoutProposerSeal(BytesValue.wrap(new byte[32]), validatorList);
|
||||
final Bytes extraData =
|
||||
CliqueExtraData.createWithoutProposerSeal(Bytes.wrap(new byte[32]), validatorList);
|
||||
final Address a1 = Util.publicKeyToAddress(otherKeyPair.getPublicKey());
|
||||
voteProposer.auth(a1);
|
||||
final Address coinbase = AddressHelpers.ofValue(1);
|
||||
@@ -203,8 +203,8 @@ public class CliqueBlockCreatorTest {
|
||||
// ensure that the next block is epoch
|
||||
epochManager = new EpochManager(1);
|
||||
|
||||
final BytesValue extraData =
|
||||
CliqueExtraData.createWithoutProposerSeal(BytesValue.wrap(new byte[32]), validatorList);
|
||||
final Bytes extraData =
|
||||
CliqueExtraData.createWithoutProposerSeal(Bytes.wrap(new byte[32]), validatorList);
|
||||
final Address a1 = Address.fromHexString("5");
|
||||
voteProposer.auth(a1);
|
||||
final Address coinbase = AddressHelpers.ofValue(1);
|
||||
|
||||
@@ -44,13 +44,13 @@ import org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfigurati
|
||||
import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem;
|
||||
import org.hyperledger.besu.plugin.services.MetricsSystem;
|
||||
import org.hyperledger.besu.testutil.TestClock;
|
||||
import org.hyperledger.besu.util.bytes.BytesValue;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.function.Function;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import org.apache.tuweni.bytes.Bytes;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -88,7 +88,7 @@ public class CliqueMinerExecutorTest {
|
||||
|
||||
@Test
|
||||
public void extraDataCreatedOnEpochBlocksContainsValidators() {
|
||||
final BytesValue vanityData = generateRandomVanityData();
|
||||
final Bytes vanityData = generateRandomVanityData();
|
||||
|
||||
final CliqueMinerExecutor executor =
|
||||
new CliqueMinerExecutor(
|
||||
@@ -108,7 +108,7 @@ public class CliqueMinerExecutorTest {
|
||||
// NOTE: Passing in the *parent* block, so must be 1 less than EPOCH
|
||||
final BlockHeader header = blockHeaderBuilder.number(EPOCH_LENGTH - 1).buildHeader();
|
||||
|
||||
final BytesValue extraDataBytes = executor.calculateExtraData(header);
|
||||
final Bytes extraDataBytes = executor.calculateExtraData(header);
|
||||
|
||||
final CliqueExtraData cliqueExtraData =
|
||||
CliqueExtraData.decode(
|
||||
@@ -125,7 +125,7 @@ public class CliqueMinerExecutorTest {
|
||||
|
||||
@Test
|
||||
public void extraDataForNonEpochBlocksDoesNotContainValidaors() {
|
||||
final BytesValue vanityData = generateRandomVanityData();
|
||||
final Bytes vanityData = generateRandomVanityData();
|
||||
|
||||
final CliqueMinerExecutor executor =
|
||||
new CliqueMinerExecutor(
|
||||
@@ -145,7 +145,7 @@ public class CliqueMinerExecutorTest {
|
||||
// Parent block was epoch, so the next block should contain no validators.
|
||||
final BlockHeader header = blockHeaderBuilder.number(EPOCH_LENGTH).buildHeader();
|
||||
|
||||
final BytesValue extraDataBytes = executor.calculateExtraData(header);
|
||||
final Bytes extraDataBytes = executor.calculateExtraData(header);
|
||||
|
||||
final CliqueExtraData cliqueExtraData =
|
||||
CliqueExtraData.decode(
|
||||
@@ -161,8 +161,8 @@ public class CliqueMinerExecutorTest {
|
||||
|
||||
@Test
|
||||
public void shouldUseLatestVanityData() {
|
||||
final BytesValue initialVanityData = generateRandomVanityData();
|
||||
final BytesValue modifiedVanityData = generateRandomVanityData();
|
||||
final Bytes initialVanityData = generateRandomVanityData();
|
||||
final Bytes modifiedVanityData = generateRandomVanityData();
|
||||
|
||||
final CliqueMinerExecutor executor =
|
||||
new CliqueMinerExecutor(
|
||||
@@ -180,7 +180,7 @@ public class CliqueMinerExecutorTest {
|
||||
Function.identity());
|
||||
|
||||
executor.setExtraData(modifiedVanityData);
|
||||
final BytesValue extraDataBytes = executor.calculateExtraData(blockHeaderBuilder.buildHeader());
|
||||
final Bytes extraDataBytes = executor.calculateExtraData(blockHeaderBuilder.buildHeader());
|
||||
|
||||
final CliqueExtraData cliqueExtraData =
|
||||
CliqueExtraData.decode(
|
||||
@@ -192,9 +192,9 @@ public class CliqueMinerExecutorTest {
|
||||
assertThat(cliqueExtraData.getVanityData()).isEqualTo(modifiedVanityData);
|
||||
}
|
||||
|
||||
private BytesValue generateRandomVanityData() {
|
||||
private Bytes generateRandomVanityData() {
|
||||
final byte[] vanityData = new byte[32];
|
||||
random.nextBytes(vanityData);
|
||||
return BytesValue.wrap(vanityData);
|
||||
return Bytes.wrap(vanityData);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,11 +32,11 @@ import org.hyperledger.besu.ethereum.core.AddressHelpers;
|
||||
import org.hyperledger.besu.ethereum.core.BlockHeader;
|
||||
import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture;
|
||||
import org.hyperledger.besu.ethereum.core.Util;
|
||||
import org.hyperledger.besu.util.uint.UInt256;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import org.apache.tuweni.units.bigints.UInt256;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -67,7 +67,7 @@ public class CliqueDifficultyValidationRuleTest {
|
||||
@Test
|
||||
public void isTrueIfInTurnValidatorSuppliesDifficultyOfTwo() {
|
||||
final long IN_TURN_BLOCK_NUMBER = validatorList.size(); // i.e. proposer is 'in turn'
|
||||
final UInt256 REPORTED_DIFFICULTY = UInt256.of(2);
|
||||
final UInt256 REPORTED_DIFFICULTY = UInt256.valueOf(2);
|
||||
|
||||
blockHeaderBuilder.number(IN_TURN_BLOCK_NUMBER - 1L);
|
||||
final BlockHeader parentHeader =
|
||||
@@ -86,7 +86,7 @@ public class CliqueDifficultyValidationRuleTest {
|
||||
@Test
|
||||
public void isTrueIfOutTurnValidatorSuppliesDifficultyOfOne() {
|
||||
final long OUT_OF_TURN_BLOCK_NUMBER = validatorList.size() - 1L;
|
||||
final UInt256 REPORTED_DIFFICULTY = UInt256.of(1);
|
||||
final UInt256 REPORTED_DIFFICULTY = UInt256.ONE;
|
||||
|
||||
blockHeaderBuilder.number(OUT_OF_TURN_BLOCK_NUMBER - 1L);
|
||||
final BlockHeader parentHeader =
|
||||
@@ -105,7 +105,7 @@ public class CliqueDifficultyValidationRuleTest {
|
||||
@Test
|
||||
public void isFalseIfOutTurnValidatorSuppliesDifficultyOfTwo() {
|
||||
final long OUT_OF_TURN_BLOCK_NUMBER = validatorList.size() - 1L;
|
||||
final UInt256 REPORTED_DIFFICULTY = UInt256.of(2);
|
||||
final UInt256 REPORTED_DIFFICULTY = UInt256.valueOf(2);
|
||||
|
||||
blockHeaderBuilder.number(OUT_OF_TURN_BLOCK_NUMBER - 1L);
|
||||
final BlockHeader parentHeader =
|
||||
@@ -125,7 +125,7 @@ public class CliqueDifficultyValidationRuleTest {
|
||||
@Test
|
||||
public void isFalseIfInTurnValidatorSuppliesDifficultyOfOne() {
|
||||
final long IN_TURN_BLOCK_NUMBER = validatorList.size();
|
||||
final UInt256 REPORTED_DIFFICULTY = UInt256.of(1);
|
||||
final UInt256 REPORTED_DIFFICULTY = UInt256.ONE;
|
||||
|
||||
blockHeaderBuilder.number(IN_TURN_BLOCK_NUMBER - 1L);
|
||||
final BlockHeader parentHeader =
|
||||
|
||||
@@ -33,11 +33,11 @@ import org.hyperledger.besu.ethereum.core.AddressHelpers;
|
||||
import org.hyperledger.besu.ethereum.core.BlockHeader;
|
||||
import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture;
|
||||
import org.hyperledger.besu.ethereum.core.Util;
|
||||
import org.hyperledger.besu.util.bytes.BytesValue;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import org.apache.tuweni.bytes.Bytes;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -67,9 +67,8 @@ public class CliqueExtraDataValidationRuleTest {
|
||||
|
||||
@Test
|
||||
public void missingSignerFailsValidation() {
|
||||
final BytesValue extraData =
|
||||
CliqueExtraData.createWithoutProposerSeal(
|
||||
BytesValue.wrap(new byte[32]), Lists.newArrayList());
|
||||
final Bytes extraData =
|
||||
CliqueExtraData.createWithoutProposerSeal(Bytes.wrap(new byte[32]), Lists.newArrayList());
|
||||
|
||||
final BlockHeaderTestFixture headerBuilder = new BlockHeaderTestFixture();
|
||||
final BlockHeader parent = headerBuilder.number(1).buildHeader();
|
||||
|
||||
@@ -36,11 +36,11 @@ import org.hyperledger.besu.ethereum.core.Address;
|
||||
import org.hyperledger.besu.ethereum.core.BlockHeader;
|
||||
import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture;
|
||||
import org.hyperledger.besu.ethereum.core.Hash;
|
||||
import org.hyperledger.besu.util.bytes.BytesValue;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.apache.tuweni.bytes.Bytes;
|
||||
import org.assertj.core.api.AssertionsForClassTypes;
|
||||
import org.bouncycastle.util.encoders.Hex;
|
||||
import org.junit.Before;
|
||||
@@ -76,7 +76,7 @@ public class CliqueGetSignersAtHashTest {
|
||||
blockHeader =
|
||||
new BlockHeaderTestFixture()
|
||||
.blockHeaderFunctions(new CliqueBlockHeaderFunctions())
|
||||
.extraData(BytesValue.wrap(genesisBlockExtraData))
|
||||
.extraData(Bytes.wrap(genesisBlockExtraData))
|
||||
.buildHeader();
|
||||
|
||||
validators =
|
||||
|
||||
@@ -34,11 +34,11 @@ import org.hyperledger.besu.ethereum.core.Address;
|
||||
import org.hyperledger.besu.ethereum.core.BlockHeader;
|
||||
import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture;
|
||||
import org.hyperledger.besu.ethereum.core.Hash;
|
||||
import org.hyperledger.besu.util.bytes.BytesValue;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.apache.tuweni.bytes.Bytes;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -63,7 +63,7 @@ public class CliqueGetSignersTest {
|
||||
|
||||
final String genesisBlockExtraData =
|
||||
"52657370656374206d7920617574686f7269746168207e452e436172746d616e42eb768f2244c8811c63729a21a3569731535f067ffc57839b00206d1ad20c69a1981b489f772031b279182d99e65703f0076e4812653aab85fca0f00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000";
|
||||
final BytesValue bufferToInject = BytesValue.fromHexString(genesisBlockExtraData);
|
||||
final Bytes bufferToInject = Bytes.fromHexString(genesisBlockExtraData);
|
||||
final BlockHeaderTestFixture blockHeaderTestFixture = new BlockHeaderTestFixture();
|
||||
blockHeader = blockHeaderTestFixture.extraData(bufferToInject).buildHeader();
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@ dependencies {
|
||||
implementation project(':crypto')
|
||||
implementation project(':util')
|
||||
|
||||
implementation 'org.apache.tuweni:tuweni-bytes'
|
||||
implementation 'com.fasterxml.jackson.core:jackson-databind'
|
||||
implementation 'com.google.guava:guava'
|
||||
|
||||
|
||||
@@ -14,14 +14,13 @@
|
||||
*/
|
||||
package org.hyperledger.besu.consensus.common;
|
||||
|
||||
import org.hyperledger.besu.util.bytes.BytesValue;
|
||||
import org.hyperledger.besu.util.bytes.BytesValues;
|
||||
import org.apache.tuweni.bytes.Bytes;
|
||||
|
||||
public class ConsensusHelpers {
|
||||
|
||||
public static BytesValue zeroLeftPad(final BytesValue input, final int requiredLength) {
|
||||
public static Bytes zeroLeftPad(final Bytes input, final int requiredLength) {
|
||||
final int paddingByteCount = Math.max(0, requiredLength - input.size());
|
||||
return BytesValues.concatenate(BytesValue.wrap(new byte[paddingByteCount]), input)
|
||||
return Bytes.concatenate(Bytes.wrap(new byte[paddingByteCount]), input)
|
||||
.slice(0, requiredLength);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,10 +26,10 @@ import org.hyperledger.besu.ethereum.core.Block;
|
||||
import org.hyperledger.besu.ethereum.core.BlockBody;
|
||||
import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture;
|
||||
import org.hyperledger.besu.ethereum.core.Hash;
|
||||
import org.hyperledger.besu.util.bytes.BytesValue;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.tuweni.bytes.Bytes;
|
||||
import org.assertj.core.util.Lists;
|
||||
import org.junit.Before;
|
||||
|
||||
@@ -57,7 +57,7 @@ public class VoteTallyCacheTestBase {
|
||||
for (int i = 0; i < 3; i++) {
|
||||
validators.add(AddressHelpers.ofValue(i));
|
||||
}
|
||||
headerBuilder.extraData(BytesValue.wrap(new byte[32]));
|
||||
headerBuilder.extraData(Bytes.wrap(new byte[32]));
|
||||
|
||||
genesisBlock = createEmptyBlock(0, Hash.ZERO);
|
||||
|
||||
|
||||
@@ -39,6 +39,8 @@ dependencies {
|
||||
implementation project(':ethereum:p2p')
|
||||
implementation project(':services:kvstore')
|
||||
|
||||
implementation 'org.apache.tuweni:tuweni-bytes'
|
||||
implementation 'org.apache.tuweni:tuweni-units'
|
||||
implementation 'io.vertx:vertx-core'
|
||||
implementation 'com.google.guava:guava'
|
||||
|
||||
|
||||
@@ -20,11 +20,12 @@ import static org.mockito.Mockito.when;
|
||||
|
||||
import org.hyperledger.besu.ethereum.p2p.rlpx.connections.PeerConnection;
|
||||
import org.hyperledger.besu.ethereum.p2p.rlpx.wire.PeerInfo;
|
||||
import org.hyperledger.besu.util.bytes.BytesValue;
|
||||
|
||||
import org.apache.tuweni.bytes.Bytes;
|
||||
|
||||
public class StubbedPeerConnection {
|
||||
|
||||
public static PeerConnection create(final BytesValue nodeId) {
|
||||
public static PeerConnection create(final Bytes nodeId) {
|
||||
PeerConnection peerConnection = mock(PeerConnection.class);
|
||||
PeerInfo peerInfo = new PeerInfo(0, "IbftIntTestPeer", emptyList(), 0, nodeId);
|
||||
when(peerConnection.getPeerInfo()).thenReturn(peerInfo);
|
||||
|
||||
@@ -72,8 +72,6 @@ import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem;
|
||||
import org.hyperledger.besu.plugin.services.MetricsSystem;
|
||||
import org.hyperledger.besu.testutil.TestClock;
|
||||
import org.hyperledger.besu.util.Subscribers;
|
||||
import org.hyperledger.besu.util.bytes.BytesValue;
|
||||
import org.hyperledger.besu.util.uint.UInt256;
|
||||
|
||||
import java.time.Clock;
|
||||
import java.time.Instant;
|
||||
@@ -86,6 +84,8 @@ import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
import org.apache.tuweni.bytes.Bytes;
|
||||
import org.apache.tuweni.units.bigints.UInt256;
|
||||
|
||||
public class TestContextBuilder {
|
||||
|
||||
@@ -237,11 +237,7 @@ public class TestContextBuilder {
|
||||
final BlockHeaderTestFixture headerTestFixture = new BlockHeaderTestFixture();
|
||||
final IbftExtraData extraData =
|
||||
new IbftExtraData(
|
||||
BytesValue.wrap(new byte[32]),
|
||||
Collections.emptyList(),
|
||||
Optional.empty(),
|
||||
0,
|
||||
validators);
|
||||
Bytes.wrap(new byte[32]), Collections.emptyList(), Optional.empty(), 0, validators);
|
||||
headerTestFixture.extraData(extraData.encode());
|
||||
headerTestFixture.mixHash(IbftHelpers.EXPECTED_MIX_HASH);
|
||||
headerTestFixture.difficulty(UInt256.ONE);
|
||||
@@ -272,7 +268,7 @@ public class TestContextBuilder {
|
||||
new MiningParameters(
|
||||
AddressHelpers.ofValue(1),
|
||||
Wei.ZERO,
|
||||
BytesValue.wrap("Ibft Int tests".getBytes(UTF_8)),
|
||||
Bytes.wrap("Ibft Int tests".getBytes(UTF_8)),
|
||||
true);
|
||||
|
||||
final StubGenesisConfigOptions genesisConfigOptions = new StubGenesisConfigOptions();
|
||||
|
||||
@@ -39,13 +39,13 @@ import org.hyperledger.besu.ethereum.core.Hash;
|
||||
import org.hyperledger.besu.ethereum.p2p.rlpx.connections.PeerConnection;
|
||||
import org.hyperledger.besu.ethereum.p2p.rlpx.wire.DefaultMessage;
|
||||
import org.hyperledger.besu.ethereum.p2p.rlpx.wire.MessageData;
|
||||
import org.hyperledger.besu.util.bytes.BytesValue;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import org.apache.tuweni.bytes.Bytes;
|
||||
|
||||
// Each "inject" function returns the SignedPayload representation of the transmitted message.
|
||||
public class ValidatorPeer {
|
||||
@@ -66,7 +66,7 @@ public class ValidatorPeer {
|
||||
this.nodeKeys = nodeParams.getNodeKeyPair();
|
||||
this.nodeAddress = nodeParams.getAddress();
|
||||
this.messageFactory = messageFactory;
|
||||
final BytesValue nodeId = nodeKeys.getPublicKey().getEncodedBytes();
|
||||
final Bytes nodeId = nodeKeys.getPublicKey().getEncodedBytes();
|
||||
this.peerConnection = StubbedPeerConnection.create(nodeId);
|
||||
this.localEventMultiplexer = localEventMultiplexer;
|
||||
}
|
||||
|
||||
@@ -35,12 +35,12 @@ import org.hyperledger.besu.ethereum.core.Hash;
|
||||
import org.hyperledger.besu.ethereum.core.Util;
|
||||
import org.hyperledger.besu.ethereum.p2p.rlpx.wire.MessageData;
|
||||
import org.hyperledger.besu.ethereum.p2p.rlpx.wire.RawMessage;
|
||||
import org.hyperledger.besu.util.bytes.BytesValue;
|
||||
|
||||
import java.time.Clock;
|
||||
import java.time.Instant;
|
||||
import java.time.ZoneId;
|
||||
|
||||
import org.apache.tuweni.bytes.Bytes;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -80,7 +80,7 @@ public class SpuriousBehaviourTest {
|
||||
|
||||
@Test
|
||||
public void badlyFormedRlpDoesNotPreventOngoingIbftOperation() {
|
||||
final MessageData illegalCommitMsg = new RawMessage(IbftV2.PREPARE, BytesValue.EMPTY);
|
||||
final MessageData illegalCommitMsg = new RawMessage(IbftV2.PREPARE, Bytes.EMPTY);
|
||||
peers.getNonProposing(0).injectMessage(illegalCommitMsg);
|
||||
|
||||
peers.getProposer().injectProposal(roundId, proposedBlock);
|
||||
@@ -89,7 +89,7 @@ public class SpuriousBehaviourTest {
|
||||
|
||||
@Test
|
||||
public void messageWithIllegalMessageCodeAreDiscardedAndDoNotPreventOngoingIbftOperation() {
|
||||
final MessageData illegalCommitMsg = new RawMessage(IbftV2.MESSAGE_SPACE, BytesValue.EMPTY);
|
||||
final MessageData illegalCommitMsg = new RawMessage(IbftV2.MESSAGE_SPACE, Bytes.EMPTY);
|
||||
peers.getNonProposing(0).injectMessage(illegalCommitMsg);
|
||||
|
||||
peers.getProposer().injectProposal(roundId, proposedBlock);
|
||||
|
||||
@@ -20,12 +20,13 @@ import org.hyperledger.besu.ethereum.core.BlockHeaderBuilder;
|
||||
import org.hyperledger.besu.ethereum.core.Hash;
|
||||
import org.hyperledger.besu.ethereum.core.Util;
|
||||
import org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput;
|
||||
import org.hyperledger.besu.util.bytes.BytesValue;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.tuweni.bytes.Bytes;
|
||||
|
||||
public class IbftBlockHashing {
|
||||
|
||||
/**
|
||||
@@ -78,8 +79,8 @@ public class IbftBlockHashing {
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private static BytesValue serializeHeader(
|
||||
final BlockHeader header, final Supplier<BytesValue> extraDataSerializer) {
|
||||
private static Bytes serializeHeader(
|
||||
final BlockHeader header, final Supplier<Bytes> extraDataSerializer) {
|
||||
|
||||
// create a block header which is a copy of the header supplied as parameter except of the
|
||||
// extraData field
|
||||
@@ -88,7 +89,7 @@ public class IbftBlockHashing {
|
||||
|
||||
// set the extraData field using the supplied extraDataSerializer if the block height is not 0
|
||||
if (header.getNumber() == BlockHeader.GENESIS_BLOCK_NUMBER) {
|
||||
builder.extraData(header.getExtraData());
|
||||
builder.extraData(header.internalGetExtraData());
|
||||
} else {
|
||||
builder.extraData(extraDataSerializer.get());
|
||||
}
|
||||
|
||||
@@ -48,6 +48,6 @@ public class IbftBlockHeaderFunctions implements BlockHeaderFunctions {
|
||||
|
||||
@Override
|
||||
public IbftExtraData parseExtraData(final BlockHeader header) {
|
||||
return IbftExtraData.decodeRaw(header.getExtraData());
|
||||
return IbftExtraData.decodeRaw(header.internalGetExtraData());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,8 @@ import org.hyperledger.besu.ethereum.mainnet.headervalidationrules.GasLimitRange
|
||||
import org.hyperledger.besu.ethereum.mainnet.headervalidationrules.GasUsageValidationRule;
|
||||
import org.hyperledger.besu.ethereum.mainnet.headervalidationrules.TimestampBoundedByFutureParameter;
|
||||
import org.hyperledger.besu.ethereum.mainnet.headervalidationrules.TimestampMoreRecentThanParent;
|
||||
import org.hyperledger.besu.util.uint.UInt256;
|
||||
|
||||
import org.apache.tuweni.units.bigints.UInt256;
|
||||
|
||||
public class IbftBlockHeaderValidationRulesetFactory {
|
||||
|
||||
@@ -53,7 +54,7 @@ public class IbftBlockHeaderValidationRulesetFactory {
|
||||
"OmmersHash", BlockHeader::getOmmersHash, Hash.EMPTY_LIST_HASH))
|
||||
.addRule(
|
||||
new ConstantFieldValidationRule<>(
|
||||
"Difficulty", BlockHeader::getDifficulty, UInt256.ONE))
|
||||
"Difficulty", BlockHeader::internalGetDifficulty, UInt256.ONE))
|
||||
.addRule(new ConstantFieldValidationRule<>("Nonce", BlockHeader::getNonce, 0L))
|
||||
.addRule(new IbftValidatorsValidationRule())
|
||||
.addRule(new IbftCoinbaseValidationRule())
|
||||
|
||||
@@ -23,7 +23,6 @@ import org.hyperledger.besu.ethereum.core.ParsedExtraData;
|
||||
import org.hyperledger.besu.ethereum.rlp.BytesValueRLPInput;
|
||||
import org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput;
|
||||
import org.hyperledger.besu.ethereum.rlp.RLPInput;
|
||||
import org.hyperledger.besu.util.bytes.BytesValue;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
@@ -33,6 +32,7 @@ import java.util.StringJoiner;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.tuweni.bytes.Bytes;
|
||||
|
||||
/**
|
||||
* Represents the data structure stored in the extraData field of the BlockHeader used when
|
||||
@@ -43,14 +43,14 @@ public class IbftExtraData implements ParsedExtraData {
|
||||
|
||||
public static final int EXTRA_VANITY_LENGTH = 32;
|
||||
|
||||
private final BytesValue vanityData;
|
||||
private final Bytes vanityData;
|
||||
private final Collection<Signature> seals;
|
||||
private final Optional<Vote> vote;
|
||||
private final int round;
|
||||
private final Collection<Address> validators;
|
||||
|
||||
public IbftExtraData(
|
||||
final BytesValue vanityData,
|
||||
final Bytes vanityData,
|
||||
final Collection<Signature> seals,
|
||||
final Optional<Vote> vote,
|
||||
final int round,
|
||||
@@ -69,7 +69,7 @@ public class IbftExtraData implements ParsedExtraData {
|
||||
|
||||
public static IbftExtraData fromAddresses(final Collection<Address> addresses) {
|
||||
return new IbftExtraData(
|
||||
BytesValue.wrap(new byte[32]), Collections.emptyList(), Optional.empty(), 0, addresses);
|
||||
Bytes.wrap(new byte[32]), Collections.emptyList(), Optional.empty(), 0, addresses);
|
||||
}
|
||||
|
||||
public static IbftExtraData decode(final BlockHeader blockHeader) {
|
||||
@@ -80,18 +80,18 @@ public class IbftExtraData implements ParsedExtraData {
|
||||
LOG.warn(
|
||||
"Expected a IbftExtraData instance but got {}. Reparsing required.",
|
||||
inputExtraData != null ? inputExtraData.getClass().getName() : "null");
|
||||
return decodeRaw(blockHeader.getExtraData());
|
||||
return decodeRaw(blockHeader.internalGetExtraData());
|
||||
}
|
||||
|
||||
static IbftExtraData decodeRaw(final BytesValue input) {
|
||||
static IbftExtraData decodeRaw(final Bytes input) {
|
||||
if (input.isEmpty()) {
|
||||
throw new IllegalArgumentException("Invalid BytesValue supplied - Ibft Extra Data required.");
|
||||
throw new IllegalArgumentException("Invalid Bytes supplied - Ibft Extra Data required.");
|
||||
}
|
||||
|
||||
final RLPInput rlpInput = new BytesValueRLPInput(input, false);
|
||||
|
||||
rlpInput.enterList(); // This accounts for the "root node" which contains IBFT data items.
|
||||
final BytesValue vanityData = rlpInput.readBytesValue();
|
||||
final Bytes vanityData = rlpInput.readBytes();
|
||||
final List<Address> validators = rlpInput.readList(Address::readFrom);
|
||||
final Optional<Vote> vote;
|
||||
if (rlpInput.nextIsNull()) {
|
||||
@@ -101,21 +101,21 @@ public class IbftExtraData implements ParsedExtraData {
|
||||
vote = Optional.of(Vote.readFrom(rlpInput));
|
||||
}
|
||||
final int round = rlpInput.readInt();
|
||||
final List<Signature> seals = rlpInput.readList(rlp -> Signature.decode(rlp.readBytesValue()));
|
||||
final List<Signature> seals = rlpInput.readList(rlp -> Signature.decode(rlp.readBytes()));
|
||||
rlpInput.leaveList();
|
||||
|
||||
return new IbftExtraData(vanityData, seals, vote, round, validators);
|
||||
}
|
||||
|
||||
public BytesValue encode() {
|
||||
public Bytes encode() {
|
||||
return encode(EncodingType.ALL);
|
||||
}
|
||||
|
||||
public BytesValue encodeWithoutCommitSeals() {
|
||||
public Bytes encodeWithoutCommitSeals() {
|
||||
return encode(EncodingType.EXCLUDE_COMMIT_SEALS);
|
||||
}
|
||||
|
||||
public BytesValue encodeWithoutCommitSealsAndRoundNumber() {
|
||||
public Bytes encodeWithoutCommitSealsAndRoundNumber() {
|
||||
return encode(EncodingType.EXCLUDE_COMMIT_SEALS_AND_ROUND_NUMBER);
|
||||
}
|
||||
|
||||
@@ -125,12 +125,12 @@ public class IbftExtraData implements ParsedExtraData {
|
||||
EXCLUDE_COMMIT_SEALS_AND_ROUND_NUMBER
|
||||
}
|
||||
|
||||
private BytesValue encode(final EncodingType encodingType) {
|
||||
private Bytes encode(final EncodingType encodingType) {
|
||||
|
||||
final BytesValueRLPOutput encoder = new BytesValueRLPOutput();
|
||||
encoder.startList();
|
||||
encoder.writeBytesValue(vanityData);
|
||||
encoder.writeList(validators, (validator, rlp) -> rlp.writeBytesValue(validator));
|
||||
encoder.writeBytes(vanityData);
|
||||
encoder.writeList(validators, (validator, rlp) -> rlp.writeBytes(validator));
|
||||
if (vote.isPresent()) {
|
||||
vote.get().writeTo(encoder);
|
||||
} else {
|
||||
@@ -140,7 +140,7 @@ public class IbftExtraData implements ParsedExtraData {
|
||||
if (encodingType != EncodingType.EXCLUDE_COMMIT_SEALS_AND_ROUND_NUMBER) {
|
||||
encoder.writeInt(round);
|
||||
if (encodingType != EncodingType.EXCLUDE_COMMIT_SEALS) {
|
||||
encoder.writeList(seals, (committer, rlp) -> rlp.writeBytesValue(committer.encodedBytes()));
|
||||
encoder.writeList(seals, (committer, rlp) -> rlp.writeBytes(committer.encodedBytes()));
|
||||
}
|
||||
}
|
||||
encoder.endList();
|
||||
@@ -151,16 +151,12 @@ public class IbftExtraData implements ParsedExtraData {
|
||||
public static String createGenesisExtraDataString(final List<Address> validators) {
|
||||
final IbftExtraData extraData =
|
||||
new IbftExtraData(
|
||||
BytesValue.wrap(new byte[32]),
|
||||
Collections.emptyList(),
|
||||
Optional.empty(),
|
||||
0,
|
||||
validators);
|
||||
Bytes.wrap(new byte[32]), Collections.emptyList(), Optional.empty(), 0, validators);
|
||||
return extraData.encode().toString();
|
||||
}
|
||||
|
||||
// Accessors
|
||||
public BytesValue getVanityData() {
|
||||
public Bytes getVanityData() {
|
||||
return vanityData;
|
||||
}
|
||||
|
||||
|
||||
@@ -84,7 +84,7 @@ public class Vote {
|
||||
|
||||
public void writeTo(final RLPOutput rlpOutput) {
|
||||
rlpOutput.startList();
|
||||
rlpOutput.writeBytesValue(recipient);
|
||||
rlpOutput.writeBytes(recipient);
|
||||
rlpOutput.writeByte(voteToValue.get(voteType));
|
||||
rlpOutput.endList();
|
||||
}
|
||||
|
||||
@@ -27,7 +27,6 @@ import org.hyperledger.besu.ethereum.core.MiningParameters;
|
||||
import org.hyperledger.besu.ethereum.core.Wei;
|
||||
import org.hyperledger.besu.ethereum.eth.transactions.PendingTransactions;
|
||||
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
|
||||
import org.hyperledger.besu.util.bytes.BytesValue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
@@ -35,6 +34,8 @@ import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.apache.tuweni.bytes.Bytes;
|
||||
|
||||
public class IbftBlockCreatorFactory {
|
||||
|
||||
private final Function<Long, Long> gasLimitCalculator;
|
||||
@@ -43,7 +44,7 @@ public class IbftBlockCreatorFactory {
|
||||
protected final ProtocolSchedule<IbftContext> protocolSchedule;
|
||||
private final Address localAddress;
|
||||
|
||||
private volatile BytesValue vanityData;
|
||||
private volatile Bytes vanityData;
|
||||
private volatile Wei minTransactionGasPrice;
|
||||
|
||||
public IbftBlockCreatorFactory(
|
||||
@@ -74,19 +75,19 @@ public class IbftBlockCreatorFactory {
|
||||
parentHeader);
|
||||
}
|
||||
|
||||
public void setExtraData(final BytesValue extraData) {
|
||||
public void setExtraData(final Bytes extraData) {
|
||||
this.vanityData = extraData.copy();
|
||||
}
|
||||
|
||||
public void setMinTransactionGasPrice(final Wei minTransactionGasPrice) {
|
||||
this.minTransactionGasPrice = minTransactionGasPrice.copy();
|
||||
this.minTransactionGasPrice = minTransactionGasPrice;
|
||||
}
|
||||
|
||||
public Wei getMinTransactionGasPrice() {
|
||||
return minTransactionGasPrice;
|
||||
}
|
||||
|
||||
public BytesValue createExtraData(final int round, final BlockHeader parentHeader) {
|
||||
public Bytes createExtraData(final int round, final BlockHeader parentHeader) {
|
||||
final VoteTally voteTally =
|
||||
protocolContext
|
||||
.getConsensusState()
|
||||
|
||||
@@ -30,13 +30,13 @@ import org.hyperledger.besu.ethereum.core.Block;
|
||||
import org.hyperledger.besu.ethereum.core.BlockHeader;
|
||||
import org.hyperledger.besu.ethereum.core.Transaction;
|
||||
import org.hyperledger.besu.ethereum.core.Wei;
|
||||
import org.hyperledger.besu.util.bytes.BytesValue;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.tuweni.bytes.Bytes;
|
||||
|
||||
public class IbftMiningCoordinator implements MiningCoordinator, BlockAddedObserver {
|
||||
|
||||
@@ -126,7 +126,7 @@ public class IbftMiningCoordinator implements MiningCoordinator, BlockAddedObser
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setExtraData(final BytesValue extraData) {
|
||||
public void setExtraData(final Bytes extraData) {
|
||||
blockCreatorFactory.setExtraData(extraData);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,12 +16,13 @@ package org.hyperledger.besu.consensus.ibft.messagedata;
|
||||
|
||||
import org.hyperledger.besu.ethereum.p2p.rlpx.wire.AbstractMessageData;
|
||||
import org.hyperledger.besu.ethereum.p2p.rlpx.wire.MessageData;
|
||||
import org.hyperledger.besu.util.bytes.BytesValue;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.apache.tuweni.bytes.Bytes;
|
||||
|
||||
public abstract class AbstractIbftMessageData extends AbstractMessageData {
|
||||
protected AbstractIbftMessageData(final BytesValue data) {
|
||||
protected AbstractIbftMessageData(final Bytes data) {
|
||||
super(data);
|
||||
}
|
||||
|
||||
@@ -29,7 +30,7 @@ public abstract class AbstractIbftMessageData extends AbstractMessageData {
|
||||
final MessageData messageData,
|
||||
final int messageCode,
|
||||
final Class<T> clazz,
|
||||
final Function<BytesValue, T> constructor) {
|
||||
final Function<Bytes, T> constructor) {
|
||||
if (clazz.isInstance(messageData)) {
|
||||
@SuppressWarnings("unchecked")
|
||||
T castMessage = (T) messageData;
|
||||
|
||||
@@ -16,13 +16,14 @@ package org.hyperledger.besu.consensus.ibft.messagedata;
|
||||
|
||||
import org.hyperledger.besu.consensus.ibft.messagewrappers.Commit;
|
||||
import org.hyperledger.besu.ethereum.p2p.rlpx.wire.MessageData;
|
||||
import org.hyperledger.besu.util.bytes.BytesValue;
|
||||
|
||||
import org.apache.tuweni.bytes.Bytes;
|
||||
|
||||
public class CommitMessageData extends AbstractIbftMessageData {
|
||||
|
||||
private static final int MESSAGE_CODE = IbftV2.COMMIT;
|
||||
|
||||
private CommitMessageData(final BytesValue data) {
|
||||
private CommitMessageData(final Bytes data) {
|
||||
super(data);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,13 +16,14 @@ package org.hyperledger.besu.consensus.ibft.messagedata;
|
||||
|
||||
import org.hyperledger.besu.consensus.ibft.messagewrappers.Prepare;
|
||||
import org.hyperledger.besu.ethereum.p2p.rlpx.wire.MessageData;
|
||||
import org.hyperledger.besu.util.bytes.BytesValue;
|
||||
|
||||
import org.apache.tuweni.bytes.Bytes;
|
||||
|
||||
public class PrepareMessageData extends AbstractIbftMessageData {
|
||||
|
||||
private static final int MESSAGE_CODE = IbftV2.PREPARE;
|
||||
|
||||
private PrepareMessageData(final BytesValue data) {
|
||||
private PrepareMessageData(final Bytes data) {
|
||||
super(data);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,13 +16,14 @@ package org.hyperledger.besu.consensus.ibft.messagedata;
|
||||
|
||||
import org.hyperledger.besu.consensus.ibft.messagewrappers.Proposal;
|
||||
import org.hyperledger.besu.ethereum.p2p.rlpx.wire.MessageData;
|
||||
import org.hyperledger.besu.util.bytes.BytesValue;
|
||||
|
||||
import org.apache.tuweni.bytes.Bytes;
|
||||
|
||||
public class ProposalMessageData extends AbstractIbftMessageData {
|
||||
|
||||
private static final int MESSAGE_CODE = IbftV2.PROPOSAL;
|
||||
|
||||
private ProposalMessageData(final BytesValue data) {
|
||||
private ProposalMessageData(final Bytes data) {
|
||||
super(data);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,13 +16,14 @@ package org.hyperledger.besu.consensus.ibft.messagedata;
|
||||
|
||||
import org.hyperledger.besu.consensus.ibft.messagewrappers.RoundChange;
|
||||
import org.hyperledger.besu.ethereum.p2p.rlpx.wire.MessageData;
|
||||
import org.hyperledger.besu.util.bytes.BytesValue;
|
||||
|
||||
import org.apache.tuweni.bytes.Bytes;
|
||||
|
||||
public class RoundChangeMessageData extends AbstractIbftMessageData {
|
||||
|
||||
private static final int MESSAGE_CODE = IbftV2.ROUND_CHANGE;
|
||||
|
||||
private RoundChangeMessageData(final BytesValue data) {
|
||||
private RoundChangeMessageData(final Bytes data) {
|
||||
super(data);
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,8 @@ import org.hyperledger.besu.consensus.ibft.payload.SignedData;
|
||||
import org.hyperledger.besu.crypto.SECP256K1.Signature;
|
||||
import org.hyperledger.besu.ethereum.core.Hash;
|
||||
import org.hyperledger.besu.ethereum.rlp.RLP;
|
||||
import org.hyperledger.besu.util.bytes.BytesValue;
|
||||
|
||||
import org.apache.tuweni.bytes.Bytes;
|
||||
|
||||
public class Commit extends IbftMessage<CommitPayload> {
|
||||
|
||||
@@ -35,7 +36,7 @@ public class Commit extends IbftMessage<CommitPayload> {
|
||||
return getPayload().getDigest();
|
||||
}
|
||||
|
||||
public static Commit decode(final BytesValue data) {
|
||||
public static Commit decode(final Bytes data) {
|
||||
return new Commit(SignedData.readSignedCommitPayloadFrom(RLP.input(data)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,10 +21,11 @@ import org.hyperledger.besu.consensus.ibft.payload.RoundSpecific;
|
||||
import org.hyperledger.besu.consensus.ibft.payload.SignedData;
|
||||
import org.hyperledger.besu.ethereum.core.Address;
|
||||
import org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput;
|
||||
import org.hyperledger.besu.util.bytes.BytesValue;
|
||||
|
||||
import java.util.StringJoiner;
|
||||
|
||||
import org.apache.tuweni.bytes.Bytes;
|
||||
|
||||
public class IbftMessage<P extends Payload> implements Authored, RoundSpecific {
|
||||
|
||||
private final SignedData<P> payload;
|
||||
@@ -43,7 +44,7 @@ public class IbftMessage<P extends Payload> implements Authored, RoundSpecific {
|
||||
return payload.getPayload().getRoundIdentifier();
|
||||
}
|
||||
|
||||
public BytesValue encode() {
|
||||
public Bytes encode() {
|
||||
final BytesValueRLPOutput rlpOut = new BytesValueRLPOutput();
|
||||
payload.writeTo(rlpOut);
|
||||
return rlpOut.encoded();
|
||||
|
||||
@@ -18,7 +18,8 @@ import org.hyperledger.besu.consensus.ibft.payload.PreparePayload;
|
||||
import org.hyperledger.besu.consensus.ibft.payload.SignedData;
|
||||
import org.hyperledger.besu.ethereum.core.Hash;
|
||||
import org.hyperledger.besu.ethereum.rlp.RLP;
|
||||
import org.hyperledger.besu.util.bytes.BytesValue;
|
||||
|
||||
import org.apache.tuweni.bytes.Bytes;
|
||||
|
||||
public class Prepare extends IbftMessage<PreparePayload> {
|
||||
|
||||
@@ -30,7 +31,7 @@ public class Prepare extends IbftMessage<PreparePayload> {
|
||||
return getPayload().getDigest();
|
||||
}
|
||||
|
||||
public static Prepare decode(final BytesValue data) {
|
||||
public static Prepare decode(final Bytes data) {
|
||||
return new Prepare(SignedData.readSignedPreparePayloadFrom(RLP.input(data)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,10 +23,11 @@ import org.hyperledger.besu.ethereum.core.Hash;
|
||||
import org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput;
|
||||
import org.hyperledger.besu.ethereum.rlp.RLP;
|
||||
import org.hyperledger.besu.ethereum.rlp.RLPInput;
|
||||
import org.hyperledger.besu.util.bytes.BytesValue;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import org.apache.tuweni.bytes.Bytes;
|
||||
|
||||
public class Proposal extends IbftMessage<ProposalPayload> {
|
||||
|
||||
private final Block proposedBlock;
|
||||
@@ -55,7 +56,7 @@ public class Proposal extends IbftMessage<ProposalPayload> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public BytesValue encode() {
|
||||
public Bytes encode() {
|
||||
final BytesValueRLPOutput rlpOut = new BytesValueRLPOutput();
|
||||
rlpOut.startList();
|
||||
getSignedPayload().writeTo(rlpOut);
|
||||
@@ -69,7 +70,7 @@ public class Proposal extends IbftMessage<ProposalPayload> {
|
||||
return rlpOut.encoded();
|
||||
}
|
||||
|
||||
public static Proposal decode(final BytesValue data) {
|
||||
public static Proposal decode(final Bytes data) {
|
||||
RLPInput rlpIn = RLP.input(data);
|
||||
rlpIn.enterList();
|
||||
final SignedData<ProposalPayload> payload = SignedData.readSignedProposalPayloadFrom(rlpIn);
|
||||
|
||||
@@ -23,10 +23,11 @@ import org.hyperledger.besu.ethereum.core.Block;
|
||||
import org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput;
|
||||
import org.hyperledger.besu.ethereum.rlp.RLP;
|
||||
import org.hyperledger.besu.ethereum.rlp.RLPInput;
|
||||
import org.hyperledger.besu.util.bytes.BytesValue;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import org.apache.tuweni.bytes.Bytes;
|
||||
|
||||
public class RoundChange extends IbftMessage<RoundChangePayload> {
|
||||
|
||||
private final Optional<Block> proposedBlock;
|
||||
@@ -51,7 +52,7 @@ public class RoundChange extends IbftMessage<RoundChangePayload> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public BytesValue encode() {
|
||||
public Bytes encode() {
|
||||
final BytesValueRLPOutput rlpOut = new BytesValueRLPOutput();
|
||||
rlpOut.startList();
|
||||
getSignedPayload().writeTo(rlpOut);
|
||||
@@ -64,7 +65,7 @@ public class RoundChange extends IbftMessage<RoundChangePayload> {
|
||||
return rlpOut.encoded();
|
||||
}
|
||||
|
||||
public static RoundChange decode(final BytesValue data) {
|
||||
public static RoundChange decode(final Bytes data) {
|
||||
|
||||
final RLPInput rlpIn = RLP.input(data);
|
||||
rlpIn.enterList();
|
||||
|
||||
@@ -43,7 +43,7 @@ public class CommitPayload implements Payload {
|
||||
rlpInput.enterList();
|
||||
final ConsensusRoundIdentifier roundIdentifier = ConsensusRoundIdentifier.readFrom(rlpInput);
|
||||
final Hash digest = Payload.readDigest(rlpInput);
|
||||
final Signature commitSeal = rlpInput.readBytesValue(Signature::decode);
|
||||
final Signature commitSeal = rlpInput.readBytes(Signature::decode);
|
||||
rlpInput.leaveList();
|
||||
|
||||
return new CommitPayload(roundIdentifier, digest, commitSeal);
|
||||
@@ -53,8 +53,8 @@ public class CommitPayload implements Payload {
|
||||
public void writeTo(final RLPOutput rlpOutput) {
|
||||
rlpOutput.startList();
|
||||
roundIdentifier.writeTo(rlpOutput);
|
||||
rlpOutput.writeBytesValue(digest);
|
||||
rlpOutput.writeBytesValue(commitSeal.encodedBytes());
|
||||
rlpOutput.writeBytes(digest);
|
||||
rlpOutput.writeBytes(commitSeal.encodedBytes());
|
||||
rlpOutput.endList();
|
||||
}
|
||||
|
||||
|
||||
@@ -26,10 +26,11 @@ import org.hyperledger.besu.crypto.SECP256K1.Signature;
|
||||
import org.hyperledger.besu.ethereum.core.Block;
|
||||
import org.hyperledger.besu.ethereum.core.Hash;
|
||||
import org.hyperledger.besu.ethereum.core.Util;
|
||||
import org.hyperledger.besu.util.bytes.BytesValues;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import org.apache.tuweni.bytes.Bytes;
|
||||
|
||||
public class MessageFactory {
|
||||
|
||||
private final KeyPair validatorKeyPair;
|
||||
@@ -86,9 +87,8 @@ public class MessageFactory {
|
||||
|
||||
public static Hash hashForSignature(final Payload unsignedMessageData) {
|
||||
return Hash.hash(
|
||||
BytesValues.concatenate(
|
||||
BytesValues.ofUnsignedByte(unsignedMessageData.getMessageType()),
|
||||
unsignedMessageData.encoded()));
|
||||
Bytes.concatenate(
|
||||
Bytes.of(unsignedMessageData.getMessageType()), unsignedMessageData.encoded()));
|
||||
}
|
||||
|
||||
private static Signature sign(final Payload unsignedMessageData, final KeyPair nodeKeys) {
|
||||
|
||||
@@ -18,13 +18,14 @@ import org.hyperledger.besu.ethereum.core.Hash;
|
||||
import org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput;
|
||||
import org.hyperledger.besu.ethereum.rlp.RLPInput;
|
||||
import org.hyperledger.besu.ethereum.rlp.RLPOutput;
|
||||
import org.hyperledger.besu.util.bytes.BytesValue;
|
||||
|
||||
import org.apache.tuweni.bytes.Bytes;
|
||||
|
||||
public interface Payload extends RoundSpecific {
|
||||
|
||||
void writeTo(final RLPOutput rlpOutput);
|
||||
|
||||
default BytesValue encoded() {
|
||||
default Bytes encoded() {
|
||||
BytesValueRLPOutput rlpOutput = new BytesValueRLPOutput();
|
||||
writeTo(rlpOutput);
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ public class PreparePayload implements Payload {
|
||||
public void writeTo(final RLPOutput rlpOutput) {
|
||||
rlpOutput.startList();
|
||||
roundIdentifier.writeTo(rlpOutput);
|
||||
rlpOutput.writeBytesValue(digest);
|
||||
rlpOutput.writeBytes(digest);
|
||||
rlpOutput.endList();
|
||||
}
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ public class ProposalPayload implements Payload {
|
||||
public void writeTo(final RLPOutput rlpOutput) {
|
||||
rlpOutput.startList();
|
||||
roundIdentifier.writeTo(rlpOutput);
|
||||
rlpOutput.writeBytesValue(digest);
|
||||
rlpOutput.writeBytes(digest);
|
||||
rlpOutput.endList();
|
||||
}
|
||||
|
||||
|
||||
@@ -20,11 +20,12 @@ import org.hyperledger.besu.ethereum.core.Util;
|
||||
import org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput;
|
||||
import org.hyperledger.besu.ethereum.rlp.RLPInput;
|
||||
import org.hyperledger.besu.ethereum.rlp.RLPOutput;
|
||||
import org.hyperledger.besu.util.bytes.BytesValue;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.StringJoiner;
|
||||
|
||||
import org.apache.tuweni.bytes.Bytes;
|
||||
|
||||
public class SignedData<M extends Payload> implements Authored {
|
||||
|
||||
private final Address sender;
|
||||
@@ -50,11 +51,11 @@ public class SignedData<M extends Payload> implements Authored {
|
||||
|
||||
output.startList();
|
||||
unsignedPayload.writeTo(output);
|
||||
output.writeBytesValue(signature.encodedBytes());
|
||||
output.writeBytes(signature.encodedBytes());
|
||||
output.endList();
|
||||
}
|
||||
|
||||
public BytesValue encode() {
|
||||
public Bytes encode() {
|
||||
final BytesValueRLPOutput rlpEncode = new BytesValueRLPOutput();
|
||||
writeTo(rlpEncode);
|
||||
return rlpEncode.encoded();
|
||||
@@ -110,7 +111,7 @@ public class SignedData<M extends Payload> implements Authored {
|
||||
}
|
||||
|
||||
protected static Signature readSignature(final RLPInput signedMessage) {
|
||||
return signedMessage.readBytesValue(Signature::decode);
|
||||
return signedMessage.readBytes(Signature::decode);
|
||||
}
|
||||
|
||||
protected static Address recoverSender(
|
||||
|
||||
@@ -24,11 +24,12 @@ import org.hyperledger.besu.ethereum.core.BlockHeader;
|
||||
import org.hyperledger.besu.ethereum.core.Hash;
|
||||
import org.hyperledger.besu.plugin.data.Address;
|
||||
import org.hyperledger.besu.plugin.services.query.IbftQueryService;
|
||||
import org.hyperledger.besu.util.bytes.Bytes32;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
import org.apache.tuweni.bytes.Bytes32;
|
||||
|
||||
public class IbftQueryServiceImpl extends PoaQueryServiceImpl implements IbftQueryService {
|
||||
|
||||
public IbftQueryServiceImpl(
|
||||
|
||||
@@ -28,8 +28,6 @@ import org.hyperledger.besu.ethereum.core.Hash;
|
||||
import org.hyperledger.besu.ethereum.core.LogsBloomFilter;
|
||||
import org.hyperledger.besu.ethereum.core.Util;
|
||||
import org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput;
|
||||
import org.hyperledger.besu.util.bytes.BytesValue;
|
||||
import org.hyperledger.besu.util.uint.UInt256;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@@ -37,6 +35,8 @@ import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import org.apache.tuweni.bytes.Bytes;
|
||||
import org.apache.tuweni.units.bigints.UInt256;
|
||||
import org.junit.Test;
|
||||
|
||||
public class IbftBlockHashingTest {
|
||||
@@ -46,7 +46,7 @@ public class IbftBlockHashingTest {
|
||||
Arrays.asList(Address.fromHexString("1"), Address.fromHexString("2"));
|
||||
private static final Optional<Vote> VOTE = Optional.of(Vote.authVote(Address.fromHexString("3")));
|
||||
private static final int ROUND = 0x00FEDCBA;
|
||||
private static final BytesValue VANITY_DATA = vanityBytes();
|
||||
private static final Bytes VANITY_DATA = vanityBytes();
|
||||
|
||||
private static final BlockHeader HEADER_TO_BE_HASHED = headerToBeHashed();
|
||||
private static final Hash EXPECTED_HEADER_HASH = expectedHeaderHash();
|
||||
@@ -94,7 +94,7 @@ public class IbftBlockHashingTest {
|
||||
|
||||
private static List<KeyPair> committersKeyPairs() {
|
||||
return IntStream.rangeClosed(1, 4)
|
||||
.mapToObj(i -> KeyPair.create(PrivateKey.create(UInt256.of(i).getBytes())))
|
||||
.mapToObj(i -> KeyPair.create(PrivateKey.create(UInt256.valueOf(i).toBytes())))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@@ -132,12 +132,12 @@ public class IbftBlockHashingTest {
|
||||
return builder;
|
||||
}
|
||||
|
||||
private static BytesValue vanityBytes() {
|
||||
private static Bytes vanityBytes() {
|
||||
final byte[] vanity_bytes = new byte[32];
|
||||
for (int i = 0; i < vanity_bytes.length; i++) {
|
||||
vanity_bytes[i] = (byte) i;
|
||||
}
|
||||
return BytesValue.wrap(vanity_bytes);
|
||||
return Bytes.wrap(vanity_bytes);
|
||||
}
|
||||
|
||||
private static BlockHeader headerToBeHashed() {
|
||||
|
||||
@@ -28,13 +28,13 @@ import org.hyperledger.besu.ethereum.core.Hash;
|
||||
import org.hyperledger.besu.ethereum.core.Util;
|
||||
import org.hyperledger.besu.ethereum.mainnet.BlockHeaderValidator;
|
||||
import org.hyperledger.besu.ethereum.mainnet.HeaderValidationMode;
|
||||
import org.hyperledger.besu.util.bytes.BytesValue;
|
||||
import org.hyperledger.besu.util.uint.UInt256;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.apache.tuweni.bytes.Bytes;
|
||||
import org.apache.tuweni.units.bigints.UInt256;
|
||||
import org.junit.Test;
|
||||
|
||||
public class IbftBlockHeaderValidationRulesetFactoryTest {
|
||||
@@ -211,7 +211,7 @@ public class IbftBlockHeaderValidationRulesetFactoryTest {
|
||||
getPresetHeaderBuilder(1, proposerKeyPair, validators, null).buildHeader();
|
||||
final BlockHeader blockHeader =
|
||||
getPresetHeaderBuilder(2, proposerKeyPair, validators, parentHeader)
|
||||
.difficulty(UInt256.of(5))
|
||||
.difficulty(UInt256.valueOf(5))
|
||||
.buildHeader();
|
||||
|
||||
final BlockHeaderValidator<IbftContext> validator =
|
||||
@@ -314,7 +314,7 @@ public class IbftBlockHeaderValidationRulesetFactoryTest {
|
||||
final IbftExtraData ibftExtraData =
|
||||
IbftExtraDataFixture.createExtraData(
|
||||
builder.buildHeader(),
|
||||
BytesValue.wrap(new byte[IbftExtraData.EXTRA_VANITY_LENGTH]),
|
||||
Bytes.wrap(new byte[IbftExtraData.EXTRA_VANITY_LENGTH]),
|
||||
Optional.of(Vote.authVote(Address.fromHexString("1"))),
|
||||
validators,
|
||||
singletonList(proposerKeyPair),
|
||||
|
||||
@@ -22,18 +22,19 @@ import org.hyperledger.besu.crypto.SECP256K1.Signature;
|
||||
import org.hyperledger.besu.ethereum.core.Address;
|
||||
import org.hyperledger.besu.ethereum.core.BlockHeader;
|
||||
import org.hyperledger.besu.ethereum.core.Hash;
|
||||
import org.hyperledger.besu.util.bytes.BytesValue;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import org.apache.tuweni.bytes.Bytes;
|
||||
|
||||
public class IbftExtraDataFixture {
|
||||
|
||||
public static IbftExtraData createExtraData(
|
||||
final BlockHeader header,
|
||||
final BytesValue vanityData,
|
||||
final Bytes vanityData,
|
||||
final Optional<Vote> vote,
|
||||
final List<Address> validators,
|
||||
final List<KeyPair> committerKeyPairs) {
|
||||
@@ -43,7 +44,7 @@ public class IbftExtraDataFixture {
|
||||
|
||||
public static IbftExtraData createExtraData(
|
||||
final BlockHeader header,
|
||||
final BytesValue vanityData,
|
||||
final Bytes vanityData,
|
||||
final Optional<Vote> vote,
|
||||
final List<Address> validators,
|
||||
final List<KeyPair> committerKeyPairs,
|
||||
@@ -55,7 +56,7 @@ public class IbftExtraDataFixture {
|
||||
|
||||
public static IbftExtraData createExtraData(
|
||||
final BlockHeader header,
|
||||
final BytesValue vanityData,
|
||||
final Bytes vanityData,
|
||||
final Optional<Vote> vote,
|
||||
final List<Address> validators,
|
||||
final List<KeyPair> committerKeyPairs,
|
||||
|
||||
@@ -24,7 +24,6 @@ import org.hyperledger.besu.ethereum.core.BlockHeader;
|
||||
import org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput;
|
||||
import org.hyperledger.besu.ethereum.rlp.RLPException;
|
||||
import org.hyperledger.besu.ethereum.rlp.RLPInput;
|
||||
import org.hyperledger.besu.util.bytes.BytesValue;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.util.Arrays;
|
||||
@@ -33,6 +32,7 @@ import java.util.Optional;
|
||||
import java.util.Random;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import org.apache.tuweni.bytes.Bytes;
|
||||
import org.junit.Test;
|
||||
|
||||
public class IbftExtraDataTest {
|
||||
@@ -59,7 +59,7 @@ public class IbftExtraDataTest {
|
||||
|
||||
// Create a byte buffer with no data.
|
||||
final byte[] vanity_bytes = createNonEmptyVanityData();
|
||||
final BytesValue vanity_data = BytesValue.wrap(vanity_bytes);
|
||||
final Bytes vanity_data = Bytes.wrap(vanity_bytes);
|
||||
|
||||
return new IbftExtraData(vanity_data, committerSeals, vote, round, validators);
|
||||
}
|
||||
@@ -74,23 +74,22 @@ public class IbftExtraDataTest {
|
||||
|
||||
// Create a byte buffer with no data.
|
||||
final byte[] vanity_bytes = new byte[32];
|
||||
final BytesValue vanity_data = BytesValue.wrap(vanity_bytes);
|
||||
final Bytes vanity_data = Bytes.wrap(vanity_bytes);
|
||||
|
||||
final BytesValueRLPOutput encoder = new BytesValueRLPOutput();
|
||||
encoder.startList();
|
||||
encoder.writeBytesValue(vanity_data);
|
||||
encoder.writeList(validators, (validator, rlp) -> rlp.writeBytesValue(validator));
|
||||
encoder.writeBytes(vanity_data);
|
||||
encoder.writeList(validators, (validator, rlp) -> rlp.writeBytes(validator));
|
||||
|
||||
// encoded vote
|
||||
vote.get().writeTo(encoder);
|
||||
|
||||
// This is to verify that the decoding works correctly when the round is encoded as 4 bytes
|
||||
encoder.writeBytesValue(BytesValue.wrap(roundAsByteArray));
|
||||
encoder.writeList(
|
||||
committerSeals, (committer, rlp) -> rlp.writeBytesValue(committer.encodedBytes()));
|
||||
encoder.writeBytes(Bytes.wrap(roundAsByteArray));
|
||||
encoder.writeList(committerSeals, (committer, rlp) -> rlp.writeBytes(committer.encodedBytes()));
|
||||
encoder.endList();
|
||||
|
||||
final BytesValue bufferToInject = encoder.encoded();
|
||||
final Bytes bufferToInject = encoder.encoded();
|
||||
|
||||
final IbftExtraData extraData = IbftExtraData.decodeRaw(bufferToInject);
|
||||
|
||||
@@ -113,24 +112,23 @@ public class IbftExtraDataTest {
|
||||
|
||||
// Create a byte buffer with no data.
|
||||
final byte[] vanity_bytes = new byte[32];
|
||||
final BytesValue vanity_data = BytesValue.wrap(vanity_bytes);
|
||||
final Bytes vanity_data = Bytes.wrap(vanity_bytes);
|
||||
|
||||
final BytesValueRLPOutput encoder = new BytesValueRLPOutput();
|
||||
encoder.startList();
|
||||
encoder.writeBytesValue(vanity_data);
|
||||
encoder.writeList(validators, (validator, rlp) -> rlp.writeBytesValue(validator));
|
||||
encoder.writeBytes(vanity_data);
|
||||
encoder.writeList(validators, (validator, rlp) -> rlp.writeBytes(validator));
|
||||
|
||||
// encoded vote
|
||||
vote.get().writeTo(encoder);
|
||||
|
||||
// This is to verify that the decoding throws an exception when the round number is not encoded
|
||||
// in 4 byte format
|
||||
encoder.writeBytesValue(BytesValue.wrap(roundAsByteArray));
|
||||
encoder.writeList(
|
||||
committerSeals, (committer, rlp) -> rlp.writeBytesValue(committer.encodedBytes()));
|
||||
encoder.writeBytes(Bytes.wrap(roundAsByteArray));
|
||||
encoder.writeList(committerSeals, (committer, rlp) -> rlp.writeBytes(committer.encodedBytes()));
|
||||
encoder.endList();
|
||||
|
||||
final BytesValue bufferToInject = encoder.encoded();
|
||||
final Bytes bufferToInject = encoder.encoded();
|
||||
|
||||
assertThatThrownBy(() -> IbftExtraData.decodeRaw(bufferToInject))
|
||||
.isInstanceOf(RLPException.class);
|
||||
@@ -144,22 +142,21 @@ public class IbftExtraDataTest {
|
||||
|
||||
// Create a byte buffer with no data.
|
||||
final byte[] vanity_bytes = new byte[32];
|
||||
final BytesValue vanity_data = BytesValue.wrap(vanity_bytes);
|
||||
final Bytes vanity_data = Bytes.wrap(vanity_bytes);
|
||||
|
||||
final BytesValueRLPOutput encoder = new BytesValueRLPOutput();
|
||||
encoder.startList();
|
||||
encoder.writeBytesValue(vanity_data);
|
||||
encoder.writeList(validators, (validator, rlp) -> rlp.writeBytesValue(validator));
|
||||
encoder.writeBytes(vanity_data);
|
||||
encoder.writeList(validators, (validator, rlp) -> rlp.writeBytes(validator));
|
||||
|
||||
// encode an empty vote
|
||||
encoder.writeNull();
|
||||
|
||||
encoder.writeInt(round);
|
||||
encoder.writeList(
|
||||
committerSeals, (committer, rlp) -> rlp.writeBytesValue(committer.encodedBytes()));
|
||||
encoder.writeList(committerSeals, (committer, rlp) -> rlp.writeBytes(committer.encodedBytes()));
|
||||
encoder.endList();
|
||||
|
||||
final BytesValue bufferToInject = encoder.encoded();
|
||||
final Bytes bufferToInject = encoder.encoded();
|
||||
|
||||
final IbftExtraData extraData = IbftExtraData.decodeRaw(bufferToInject);
|
||||
|
||||
@@ -179,7 +176,7 @@ public class IbftExtraDataTest {
|
||||
|
||||
// Create a byte buffer with no data.
|
||||
final byte[] vanity_bytes = new byte[32];
|
||||
final BytesValue vanity_data = BytesValue.wrap(vanity_bytes);
|
||||
final Bytes vanity_data = Bytes.wrap(vanity_bytes);
|
||||
|
||||
IbftExtraData expectedExtraData =
|
||||
new IbftExtraData(vanity_data, committerSeals, vote, round, validators);
|
||||
@@ -198,22 +195,21 @@ public class IbftExtraDataTest {
|
||||
|
||||
// Create a byte buffer with no data.
|
||||
final byte[] vanity_bytes = new byte[32];
|
||||
final BytesValue vanity_data = BytesValue.wrap(vanity_bytes);
|
||||
final Bytes vanity_data = Bytes.wrap(vanity_bytes);
|
||||
|
||||
final BytesValueRLPOutput encoder = new BytesValueRLPOutput();
|
||||
encoder.startList();
|
||||
encoder.writeBytesValue(vanity_data);
|
||||
encoder.writeList(validators, (validator, rlp) -> rlp.writeBytesValue(validator));
|
||||
encoder.writeBytes(vanity_data);
|
||||
encoder.writeList(validators, (validator, rlp) -> rlp.writeBytes(validator));
|
||||
|
||||
// encoded vote
|
||||
vote.get().writeTo(encoder);
|
||||
|
||||
encoder.writeInt(round);
|
||||
encoder.writeList(
|
||||
committerSeals, (committer, rlp) -> rlp.writeBytesValue(committer.encodedBytes()));
|
||||
encoder.writeList(committerSeals, (committer, rlp) -> rlp.writeBytes(committer.encodedBytes()));
|
||||
encoder.endList();
|
||||
|
||||
final BytesValue bufferToInject = encoder.encoded();
|
||||
final Bytes bufferToInject = encoder.encoded();
|
||||
|
||||
final IbftExtraData extraData = IbftExtraData.decodeRaw(bufferToInject);
|
||||
|
||||
@@ -232,7 +228,7 @@ public class IbftExtraDataTest {
|
||||
|
||||
// Create a byte buffer with no data.
|
||||
final byte[] vanity_bytes = new byte[32];
|
||||
final BytesValue vanity_data = BytesValue.wrap(vanity_bytes);
|
||||
final Bytes vanity_data = Bytes.wrap(vanity_bytes);
|
||||
|
||||
IbftExtraData expectedExtraData =
|
||||
new IbftExtraData(vanity_data, committerSeals, vote, round, validators);
|
||||
@@ -255,25 +251,24 @@ public class IbftExtraDataTest {
|
||||
// Create randomised vanity data.
|
||||
final byte[] vanity_bytes = createNonEmptyVanityData();
|
||||
new Random().nextBytes(vanity_bytes);
|
||||
final BytesValue vanity_data = BytesValue.wrap(vanity_bytes);
|
||||
final Bytes vanity_data = Bytes.wrap(vanity_bytes);
|
||||
|
||||
final BytesValueRLPOutput encoder = new BytesValueRLPOutput();
|
||||
encoder.startList(); // This is required to create a "root node" for all RLP'd data
|
||||
encoder.writeBytesValue(vanity_data);
|
||||
encoder.writeList(validators, (validator, rlp) -> rlp.writeBytesValue(validator));
|
||||
encoder.writeBytes(vanity_data);
|
||||
encoder.writeList(validators, (validator, rlp) -> rlp.writeBytes(validator));
|
||||
|
||||
// encoded vote
|
||||
encoder.startList();
|
||||
encoder.writeBytesValue(Address.fromHexString("1"));
|
||||
encoder.writeBytes(Address.fromHexString("1"));
|
||||
encoder.writeByte(Vote.ADD_BYTE_VALUE);
|
||||
encoder.endList();
|
||||
|
||||
encoder.writeInt(round);
|
||||
encoder.writeList(
|
||||
committerSeals, (committer, rlp) -> rlp.writeBytesValue(committer.encodedBytes()));
|
||||
encoder.writeList(committerSeals, (committer, rlp) -> rlp.writeBytes(committer.encodedBytes()));
|
||||
encoder.endList();
|
||||
|
||||
final BytesValue bufferToInject = encoder.encoded();
|
||||
final Bytes bufferToInject = encoder.encoded();
|
||||
|
||||
final IbftExtraData extraData = IbftExtraData.decodeRaw(bufferToInject);
|
||||
|
||||
@@ -298,7 +293,7 @@ public class IbftExtraDataTest {
|
||||
|
||||
// Create a byte buffer with no data.
|
||||
final byte[] vanity_bytes = createNonEmptyVanityData();
|
||||
final BytesValue vanity_data = BytesValue.wrap(vanity_bytes);
|
||||
final Bytes vanity_data = Bytes.wrap(vanity_bytes);
|
||||
|
||||
IbftExtraData expectedExtraData =
|
||||
new IbftExtraData(vanity_data, committerSeals, vote, round, validators);
|
||||
@@ -310,7 +305,7 @@ public class IbftExtraDataTest {
|
||||
|
||||
@Test
|
||||
public void encodingMatchesKnownRawHexString() {
|
||||
final BytesValue expectedRawDecoding = BytesValue.fromHexString(RAW_HEX_ENCODING_STRING);
|
||||
final Bytes expectedRawDecoding = Bytes.fromHexString(RAW_HEX_ENCODING_STRING);
|
||||
assertThat(DECODED_EXTRA_DATA_FOR_RAW_HEX_ENCODING_STRING.encode())
|
||||
.isEqualTo(expectedRawDecoding);
|
||||
}
|
||||
@@ -320,7 +315,7 @@ public class IbftExtraDataTest {
|
||||
|
||||
final IbftExtraData expectedExtraData = DECODED_EXTRA_DATA_FOR_RAW_HEX_ENCODING_STRING;
|
||||
|
||||
BytesValue rawDecoding = BytesValue.fromHexString(RAW_HEX_ENCODING_STRING);
|
||||
Bytes rawDecoding = Bytes.fromHexString(RAW_HEX_ENCODING_STRING);
|
||||
IbftExtraData actualExtraData = IbftExtraData.decodeRaw(rawDecoding);
|
||||
|
||||
assertThat(actualExtraData).isEqualToComparingFieldByField(expectedExtraData);
|
||||
@@ -339,12 +334,12 @@ public class IbftExtraDataTest {
|
||||
|
||||
// Create a byte buffer with no data.
|
||||
final byte[] vanity_bytes = createNonEmptyVanityData();
|
||||
final BytesValue vanity_data = BytesValue.wrap(vanity_bytes);
|
||||
final Bytes vanity_data = Bytes.wrap(vanity_bytes);
|
||||
|
||||
final BytesValueRLPOutput encoder = new BytesValueRLPOutput();
|
||||
encoder.startList();
|
||||
encoder.writeBytesValue(vanity_data);
|
||||
encoder.writeList(validators, (validator, rlp) -> rlp.writeBytesValue(validator));
|
||||
encoder.writeBytes(vanity_data);
|
||||
encoder.writeList(validators, (validator, rlp) -> rlp.writeBytes(validator));
|
||||
|
||||
// encoded vote
|
||||
vote.get().writeTo(encoder);
|
||||
@@ -352,9 +347,9 @@ public class IbftExtraDataTest {
|
||||
encoder.writeInt(round);
|
||||
encoder.endList();
|
||||
|
||||
BytesValue expectedEncoding = encoder.encoded();
|
||||
Bytes expectedEncoding = encoder.encoded();
|
||||
|
||||
BytesValue actualEncoding =
|
||||
Bytes actualEncoding =
|
||||
new IbftExtraData(vanity_data, committerSeals, vote, round, validators)
|
||||
.encodeWithoutCommitSeals();
|
||||
|
||||
@@ -374,21 +369,21 @@ public class IbftExtraDataTest {
|
||||
|
||||
// Create a byte buffer with no data.
|
||||
final byte[] vanity_bytes = createNonEmptyVanityData();
|
||||
final BytesValue vanity_data = BytesValue.wrap(vanity_bytes);
|
||||
final Bytes vanity_data = Bytes.wrap(vanity_bytes);
|
||||
|
||||
final BytesValueRLPOutput encoder = new BytesValueRLPOutput();
|
||||
encoder.startList();
|
||||
encoder.writeBytesValue(vanity_data);
|
||||
encoder.writeList(validators, (validator, rlp) -> rlp.writeBytesValue(validator));
|
||||
encoder.writeBytes(vanity_data);
|
||||
encoder.writeList(validators, (validator, rlp) -> rlp.writeBytes(validator));
|
||||
|
||||
// encoded vote
|
||||
vote.get().writeTo(encoder);
|
||||
|
||||
encoder.endList();
|
||||
|
||||
BytesValue expectedEncoding = encoder.encoded();
|
||||
Bytes expectedEncoding = encoder.encoded();
|
||||
|
||||
BytesValue actualEncoding =
|
||||
Bytes actualEncoding =
|
||||
new IbftExtraData(vanity_data, committerSeals, vote, round, validators)
|
||||
.encodeWithoutCommitSealsAndRoundNumber();
|
||||
|
||||
@@ -404,23 +399,22 @@ public class IbftExtraDataTest {
|
||||
|
||||
// Create a byte buffer with no data.
|
||||
final byte[] vanity_bytes = new byte[32];
|
||||
final BytesValue vanity_data = BytesValue.wrap(vanity_bytes);
|
||||
final Bytes vanity_data = Bytes.wrap(vanity_bytes);
|
||||
|
||||
final BytesValueRLPOutput encoder = new BytesValueRLPOutput();
|
||||
encoder.startList();
|
||||
encoder.writeBytesValue(vanity_data);
|
||||
encoder.writeList(validators, (validator, rlp) -> rlp.writeBytesValue(validator));
|
||||
encoder.writeBytes(vanity_data);
|
||||
encoder.writeList(validators, (validator, rlp) -> rlp.writeBytes(validator));
|
||||
|
||||
// encoded vote
|
||||
vote.get().writeTo(encoder);
|
||||
|
||||
encoder.writeInt(round);
|
||||
encoder.writeList(
|
||||
committerSeals, (committer, rlp) -> rlp.writeBytesValue(committer.encodedBytes()));
|
||||
encoder.writeList(committerSeals, (committer, rlp) -> rlp.writeBytes(committer.encodedBytes()));
|
||||
encoder.writeLong(1);
|
||||
encoder.endList();
|
||||
|
||||
final BytesValue bufferToInject = encoder.encoded();
|
||||
final Bytes bufferToInject = encoder.encoded();
|
||||
|
||||
assertThatThrownBy(() -> IbftExtraData.decodeRaw(bufferToInject))
|
||||
.isInstanceOf(RLPException.class);
|
||||
@@ -440,25 +434,24 @@ public class IbftExtraDataTest {
|
||||
|
||||
// Create a byte buffer with no data.
|
||||
final byte[] vanity_bytes = new byte[32];
|
||||
final BytesValue vanity_data = BytesValue.wrap(vanity_bytes);
|
||||
final Bytes vanity_data = Bytes.wrap(vanity_bytes);
|
||||
|
||||
final BytesValueRLPOutput encoder = new BytesValueRLPOutput();
|
||||
encoder.startList();
|
||||
encoder.writeBytesValue(vanity_data);
|
||||
encoder.writeList(validators, (validator, rlp) -> rlp.writeBytesValue(validator));
|
||||
encoder.writeBytes(vanity_data);
|
||||
encoder.writeList(validators, (validator, rlp) -> rlp.writeBytes(validator));
|
||||
|
||||
// encode vote
|
||||
encoder.startList();
|
||||
encoder.writeBytesValue(voteRecipient);
|
||||
encoder.writeBytes(voteRecipient);
|
||||
encoder.writeByte(voteType);
|
||||
encoder.endList();
|
||||
|
||||
encoder.writeInt(round);
|
||||
encoder.writeList(
|
||||
committerSeals, (committer, rlp) -> rlp.writeBytesValue(committer.encodedBytes()));
|
||||
encoder.writeList(committerSeals, (committer, rlp) -> rlp.writeBytes(committer.encodedBytes()));
|
||||
encoder.endList();
|
||||
|
||||
final BytesValue bufferToInject = encoder.encoded();
|
||||
final Bytes bufferToInject = encoder.encoded();
|
||||
|
||||
assertThatThrownBy(() -> IbftExtraData.decodeRaw(bufferToInject))
|
||||
.isInstanceOf(RLPException.class);
|
||||
@@ -466,11 +459,11 @@ public class IbftExtraDataTest {
|
||||
|
||||
@Test
|
||||
public void emptyExtraDataThrowsException() {
|
||||
final BytesValue bufferToInject = BytesValue.EMPTY;
|
||||
final Bytes bufferToInject = Bytes.EMPTY;
|
||||
|
||||
assertThatThrownBy(() -> IbftExtraData.decodeRaw(bufferToInject))
|
||||
.isInstanceOf(IllegalArgumentException.class)
|
||||
.hasMessage("Invalid BytesValue supplied - Ibft Extra Data required.");
|
||||
.hasMessage("Invalid Bytes supplied - Ibft Extra Data required.");
|
||||
}
|
||||
|
||||
private static byte[] createNonEmptyVanityData() {
|
||||
|
||||
@@ -17,8 +17,8 @@ package org.hyperledger.besu.consensus.ibft;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import org.hyperledger.besu.ethereum.p2p.rlpx.wire.MessageData;
|
||||
import org.hyperledger.besu.util.bytes.BytesValue;
|
||||
|
||||
import org.apache.tuweni.bytes.Bytes;
|
||||
import org.junit.Test;
|
||||
|
||||
public class MessageTrackerTest {
|
||||
@@ -26,11 +26,9 @@ public class MessageTrackerTest {
|
||||
|
||||
@Test
|
||||
public void duplicateMessagesAreConsideredSeen() {
|
||||
final MessageData arbitraryMessage_1 =
|
||||
createAnonymousMessageData(BytesValue.wrap(new byte[4]), 1);
|
||||
final MessageData arbitraryMessage_1 = createAnonymousMessageData(Bytes.wrap(new byte[4]), 1);
|
||||
|
||||
final MessageData arbitraryMessage_2 =
|
||||
createAnonymousMessageData(BytesValue.wrap(new byte[4]), 1);
|
||||
final MessageData arbitraryMessage_2 = createAnonymousMessageData(Bytes.wrap(new byte[4]), 1);
|
||||
|
||||
assertThat(messageTracker.hasSeenMessage(arbitraryMessage_1)).isFalse();
|
||||
assertThat(messageTracker.hasSeenMessage(arbitraryMessage_2)).isFalse();
|
||||
@@ -39,7 +37,7 @@ public class MessageTrackerTest {
|
||||
assertThat(messageTracker.hasSeenMessage(arbitraryMessage_2)).isTrue();
|
||||
}
|
||||
|
||||
private MessageData createAnonymousMessageData(final BytesValue content, final int code) {
|
||||
private MessageData createAnonymousMessageData(final Bytes content, final int code) {
|
||||
return new MessageData() {
|
||||
|
||||
@Override
|
||||
@@ -53,7 +51,7 @@ public class MessageTrackerTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
public BytesValue getData() {
|
||||
public Bytes getData() {
|
||||
return content;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -29,13 +29,14 @@ import org.hyperledger.besu.ethereum.core.Block;
|
||||
import org.hyperledger.besu.ethereum.core.BlockDataGenerator;
|
||||
import org.hyperledger.besu.ethereum.core.BlockDataGenerator.BlockOptions;
|
||||
import org.hyperledger.besu.ethereum.core.Hash;
|
||||
import org.hyperledger.besu.util.bytes.BytesValue;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.apache.tuweni.bytes.Bytes;
|
||||
|
||||
public class TestHelpers {
|
||||
|
||||
public static ConsensusRoundIdentifier createFrom(
|
||||
@@ -46,9 +47,9 @@ public class TestHelpers {
|
||||
|
||||
public static Block createProposalBlock(
|
||||
final List<Address> validators, final ConsensusRoundIdentifier roundId) {
|
||||
final BytesValue extraData =
|
||||
final Bytes extraData =
|
||||
new IbftExtraData(
|
||||
BytesValue.wrap(new byte[32]),
|
||||
Bytes.wrap(new byte[32]),
|
||||
Collections.emptyList(),
|
||||
Optional.empty(),
|
||||
roundId.getRoundNumber(),
|
||||
|
||||
@@ -26,11 +26,11 @@ import org.hyperledger.besu.consensus.ibft.network.ValidatorMulticaster;
|
||||
import org.hyperledger.besu.ethereum.core.Address;
|
||||
import org.hyperledger.besu.ethereum.core.AddressHelpers;
|
||||
import org.hyperledger.besu.ethereum.p2p.rlpx.wire.RawMessage;
|
||||
import org.hyperledger.besu.util.bytes.BytesValue;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import org.apache.tuweni.bytes.Bytes;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
@@ -42,7 +42,7 @@ public class UniqueMessageMulticasterTest {
|
||||
private final ValidatorMulticaster multicaster = mock(ValidatorMulticaster.class);
|
||||
private final UniqueMessageMulticaster uniqueMessageMulticaster =
|
||||
new UniqueMessageMulticaster(multicaster, messageTracker);
|
||||
private final RawMessage messageSent = new RawMessage(5, BytesValue.wrap(new byte[5]));
|
||||
private final RawMessage messageSent = new RawMessage(5, Bytes.wrap(new byte[5]));
|
||||
|
||||
@Test
|
||||
public void previouslySentMessageIsNotSentAgain() {
|
||||
|
||||
@@ -43,13 +43,13 @@ import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
|
||||
import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem;
|
||||
import org.hyperledger.besu.plugin.services.MetricsSystem;
|
||||
import org.hyperledger.besu.testutil.TestClock;
|
||||
import org.hyperledger.besu.util.bytes.BytesValue;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import org.apache.tuweni.bytes.Bytes;
|
||||
import org.junit.Test;
|
||||
|
||||
public class IbftBlockCreatorTest {
|
||||
@@ -95,7 +95,7 @@ public class IbftBlockCreatorTest {
|
||||
initialValidatorList.get(0),
|
||||
parent ->
|
||||
new IbftExtraData(
|
||||
BytesValue.wrap(new byte[32]),
|
||||
Bytes.wrap(new byte[32]),
|
||||
Collections.emptyList(),
|
||||
Optional.empty(),
|
||||
0,
|
||||
|
||||
@@ -30,11 +30,11 @@ import org.hyperledger.besu.ethereum.core.Block;
|
||||
import org.hyperledger.besu.ethereum.core.BlockBody;
|
||||
import org.hyperledger.besu.ethereum.core.BlockHeader;
|
||||
import org.hyperledger.besu.ethereum.core.Wei;
|
||||
import org.hyperledger.besu.util.bytes.BytesValue;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.apache.tuweni.bytes.Bytes;
|
||||
import org.assertj.core.util.Lists;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -95,7 +95,7 @@ public class IbftMiningCoordinatorTest {
|
||||
|
||||
@Test
|
||||
public void setsTheExtraData() {
|
||||
final BytesValue extraData = BytesValue.fromHexStringLenient("0x1234");
|
||||
final Bytes extraData = Bytes.fromHexStringLenient("0x1234");
|
||||
ibftMiningCoordinator.setExtraData(extraData);
|
||||
verify(ibftBlockCreatorFactory).setExtraData(extraData);
|
||||
}
|
||||
|
||||
@@ -21,11 +21,12 @@ import org.hyperledger.besu.crypto.SECP256K1.KeyPair;
|
||||
import org.hyperledger.besu.ethereum.core.Address;
|
||||
import org.hyperledger.besu.ethereum.core.BlockHeader;
|
||||
import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture;
|
||||
import org.hyperledger.besu.util.bytes.BytesValue;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.apache.tuweni.bytes.Bytes;
|
||||
|
||||
public class HeaderValidationTestHelpers {
|
||||
|
||||
public static BlockHeader createProposedBlockHeader(
|
||||
@@ -41,7 +42,7 @@ public class HeaderValidationTestHelpers {
|
||||
final IbftExtraData ibftExtraData =
|
||||
IbftExtraDataFixture.createExtraData(
|
||||
header,
|
||||
BytesValue.wrap(new byte[IbftExtraData.EXTRA_VANITY_LENGTH]),
|
||||
Bytes.wrap(new byte[IbftExtraData.EXTRA_VANITY_LENGTH]),
|
||||
Optional.of(Vote.authVote(Address.fromHexString("1"))),
|
||||
validators,
|
||||
committerKeyPairs,
|
||||
|
||||
@@ -28,12 +28,12 @@ import org.hyperledger.besu.ethereum.core.BlockHeader;
|
||||
import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture;
|
||||
import org.hyperledger.besu.ethereum.core.Hash;
|
||||
import org.hyperledger.besu.ethereum.core.Util;
|
||||
import org.hyperledger.besu.util.bytes.BytesValue;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import org.apache.tuweni.bytes.Bytes;
|
||||
import org.junit.Test;
|
||||
|
||||
public class IbftCoinbaseValidationRuleTest {
|
||||
@@ -51,7 +51,7 @@ public class IbftCoinbaseValidationRuleTest {
|
||||
final IbftExtraData ibftExtraData =
|
||||
IbftExtraDataFixture.createExtraData(
|
||||
header,
|
||||
BytesValue.wrap(new byte[IbftExtraData.EXTRA_VANITY_LENGTH]),
|
||||
Bytes.wrap(new byte[IbftExtraData.EXTRA_VANITY_LENGTH]),
|
||||
Optional.of(Vote.authVote(Address.fromHexString("1"))),
|
||||
validators,
|
||||
committerKeyPairs);
|
||||
|
||||
@@ -21,8 +21,8 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
import org.hyperledger.besu.consensus.ibft.IbftExtraData;
|
||||
import org.hyperledger.besu.ethereum.core.BlockHeader;
|
||||
import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture;
|
||||
import org.hyperledger.besu.util.bytes.BytesValue;
|
||||
|
||||
import org.apache.tuweni.bytes.Bytes;
|
||||
import org.junit.Test;
|
||||
|
||||
public class IbftVanityDataValidationRuleTest {
|
||||
@@ -40,7 +40,7 @@ public class IbftVanityDataValidationRuleTest {
|
||||
public boolean headerWithVanityDataOfSize(final int extraDataSize) {
|
||||
final IbftExtraData extraData =
|
||||
new IbftExtraData(
|
||||
BytesValue.wrap(new byte[extraDataSize]), emptyList(), empty(), 0, emptyList());
|
||||
Bytes.wrap(new byte[extraDataSize]), emptyList(), empty(), 0, emptyList());
|
||||
final BlockHeader header =
|
||||
new BlockHeaderTestFixture().extraData(extraData.encode()).buildHeader();
|
||||
|
||||
|
||||
@@ -21,8 +21,8 @@ import static org.mockito.Mockito.when;
|
||||
|
||||
import org.hyperledger.besu.consensus.ibft.messagewrappers.Commit;
|
||||
import org.hyperledger.besu.ethereum.p2p.rlpx.wire.MessageData;
|
||||
import org.hyperledger.besu.util.bytes.BytesValue;
|
||||
|
||||
import org.apache.tuweni.bytes.Bytes;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
@@ -31,7 +31,7 @@ import org.mockito.junit.MockitoJUnitRunner;
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class CommitMessageTest {
|
||||
@Mock private Commit commitPayload;
|
||||
@Mock private BytesValue messageBytes;
|
||||
@Mock private Bytes messageBytes;
|
||||
@Mock private MessageData messageData;
|
||||
@Mock private CommitMessageData commitMessage;
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user