Skip to content

Commit

Permalink
Merge with latest master
Browse files Browse the repository at this point in the history
Signed-off-by: Antoine Toulme <[email protected]>
  • Loading branch information
atoulme committed Mar 5, 2021
2 parents 66fc1c6 + a729dbd commit 7d9acd0
Show file tree
Hide file tree
Showing 26 changed files with 863 additions and 301 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* add support for keccak mining and a ecip1049_dev network [\#1882](https://github.com/hyperledger/besu/pull/1882)
### Bug Fixes
* Fixed incorrect `groupId` in published maven pom files.
* Fixed GraphQL response for missing account, return empty account instead [\#1946](https://github.com/hyperledger/besu/issues/1946)

### Early Access Features

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,8 @@ public PowAlgorithm getPowAlgorithm() {
public Map<String, Object> asMap() {
final ImmutableMap.Builder<String, Object> builder = ImmutableMap.builder();
getChainId().ifPresent(chainId -> builder.put("chainId", chainId));

// mainnet fork blocks
getHomesteadBlockNumber().ifPresent(l -> builder.put("homesteadBlock", l));
getDaoForkBlock()
.ifPresent(
Expand All @@ -372,11 +374,23 @@ public Map<String, Object> asMap() {
getIstanbulBlockNumber().ifPresent(l -> builder.put("istanbulBlock", l));
getMuirGlacierBlockNumber().ifPresent(l -> builder.put("muirGlacierBlock", l));
getBerlinBlockNumber().ifPresent(l -> builder.put("berlinBlock", l));

// classic fork blocks
getClassicForkBlock().ifPresent(l -> builder.put("classicForkBlock", l));
getEcip1015BlockNumber().ifPresent(l -> builder.put("ecip1015Block", l));
getDieHardBlockNumber().ifPresent(l -> builder.put("dieHardBlock", l));
getGothamBlockNumber().ifPresent(l -> builder.put("gothamBlock", l));
getDefuseDifficultyBombBlockNumber().ifPresent(l -> builder.put("ecip1041Block", l));
getAtlantisBlockNumber().ifPresent(l -> builder.put("atlantisBlock", l));
getAghartaBlockNumber().ifPresent(l -> builder.put("aghartaBlock", l));
getPhoenixBlockNumber().ifPresent(l -> builder.put("phoenixBlock", l));
getThanosBlockNumber().ifPresent(l -> builder.put("thanosBlock", l));
getEcip1049BlockNumber().ifPresent(l -> builder.put("ecip1049Block", l));

getEIP1559BlockNumber().ifPresent(l -> builder.put("eip1559Block", l));
getContractSizeLimit().ifPresent(l -> builder.put("contractSizeLimit", l));
getEvmStackSize().ifPresent(l -> builder.put("evmstacksize", l));
getEcip1017EraRounds().ifPresent(l -> builder.put("ecip1017EraRounds", l));
getThanosBlockNumber().ifPresent(l -> builder.put("thanosBlock", l));

if (isClique()) {
builder.put("clique", getCliqueConfigOptions().asMap());
Expand Down Expand Up @@ -468,7 +482,8 @@ public List<Long> getForks() {
getAtlantisBlockNumber(),
getAghartaBlockNumber(),
getPhoenixBlockNumber(),
getThanosBlockNumber());
getThanosBlockNumber(),
getEcip1049BlockNumber());

return forkBlockNumbers
.filter(OptionalLong::isPresent)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,16 @@ public class StubGenesisConfigOptions implements GenesisConfigOptions {
private OptionalLong berlinBlockNumber = OptionalLong.empty();
// TODO EIP-1559 change for the actual fork name when known
private final OptionalLong eip1559BlockNumber = OptionalLong.empty();
private final OptionalLong classicForkBlock = OptionalLong.empty();
private final OptionalLong ecip1015BlockNumber = OptionalLong.empty();
private final OptionalLong diehardBlockNumber = OptionalLong.empty();
private final OptionalLong gothamBlockNumber = OptionalLong.empty();
private final OptionalLong defuseDifficultyBombBlockNumber = OptionalLong.empty();
private final OptionalLong atlantisBlockNumber = OptionalLong.empty();
private final OptionalLong aghartaBlockNumber = OptionalLong.empty();
private final OptionalLong phoenixBlockNumber = OptionalLong.empty();
private final OptionalLong thanosBlockNumber = OptionalLong.empty();
private final OptionalLong ecip1049BlockNumber = OptionalLong.empty();
private OptionalLong classicForkBlock = OptionalLong.empty();
private OptionalLong ecip1015BlockNumber = OptionalLong.empty();
private OptionalLong diehardBlockNumber = OptionalLong.empty();
private OptionalLong gothamBlockNumber = OptionalLong.empty();
private OptionalLong defuseDifficultyBombBlockNumber = OptionalLong.empty();
private OptionalLong atlantisBlockNumber = OptionalLong.empty();
private OptionalLong aghartaBlockNumber = OptionalLong.empty();
private OptionalLong phoenixBlockNumber = OptionalLong.empty();
private OptionalLong thanosBlockNumber = OptionalLong.empty();
private OptionalLong ecip1049BlockNumber = OptionalLong.empty();
private Optional<BigInteger> chainId = Optional.empty();
private OptionalInt contractSizeLimit = OptionalInt.empty();
private OptionalInt stackSizeLimit = OptionalInt.empty();
Expand Down Expand Up @@ -245,6 +245,8 @@ public Optional<BigInteger> getChainId() {
public Map<String, Object> asMap() {
final ImmutableMap.Builder<String, Object> builder = ImmutableMap.builder();
getChainId().ifPresent(chainId -> builder.put("chainId", chainId));

// mainnet fork blocks
getHomesteadBlockNumber().ifPresent(l -> builder.put("homesteadBlock", l));
getDaoForkBlock()
.ifPresent(
Expand All @@ -265,6 +267,19 @@ public Map<String, Object> asMap() {
getBerlinBlockNumber().ifPresent(l -> builder.put("berlinBlock", l));
// TODO EIP-1559 change for the actual fork name when known
getEIP1559BlockNumber().ifPresent(l -> builder.put("eip1559Block", l));

// classic fork blocks
getClassicForkBlock().ifPresent(l -> builder.put("classicForkBlock", l));
getEcip1015BlockNumber().ifPresent(l -> builder.put("ecip1015Block", l));
getDieHardBlockNumber().ifPresent(l -> builder.put("dieHardBlock", l));
getGothamBlockNumber().ifPresent(l -> builder.put("gothamBlock", l));
getDefuseDifficultyBombBlockNumber().ifPresent(l -> builder.put("ecip1041Block", l));
getAtlantisBlockNumber().ifPresent(l -> builder.put("atlantisBlock", l));
getAghartaBlockNumber().ifPresent(l -> builder.put("aghartaBlock", l));
getPhoenixBlockNumber().ifPresent(l -> builder.put("phoenixBlock", l));
getThanosBlockNumber().ifPresent(l -> builder.put("thanosBlock", l));
getEcip1049BlockNumber().ifPresent(l -> builder.put("ecip1049Block", l));

getContractSizeLimit().ifPresent(l -> builder.put("contractSizeLimit", l));
getEvmStackSize().ifPresent(l -> builder.put("evmStackSize", l));
if (isClique()) {
Expand Down Expand Up @@ -362,6 +377,56 @@ public StubGenesisConfigOptions berlinBlock(final long blockNumber) {
return this;
}

public StubGenesisConfigOptions classicForkBlock(final long blockNumber) {
classicForkBlock = OptionalLong.of(blockNumber);
return this;
}

public StubGenesisConfigOptions ecip1015(final long blockNumber) {
ecip1015BlockNumber = OptionalLong.of(blockNumber);
return this;
}

public StubGenesisConfigOptions dieHard(final long blockNumber) {
diehardBlockNumber = OptionalLong.of(blockNumber);
return this;
}

public StubGenesisConfigOptions gotham(final long blockNumber) {
gothamBlockNumber = OptionalLong.of(blockNumber);
return this;
}

public StubGenesisConfigOptions defuseDifficultyBomb(final long blockNumber) {
defuseDifficultyBombBlockNumber = OptionalLong.of(blockNumber);
return this;
}

public StubGenesisConfigOptions atlantis(final long blockNumber) {
atlantisBlockNumber = OptionalLong.of(blockNumber);
return this;
}

public StubGenesisConfigOptions agharta(final long blockNumber) {
aghartaBlockNumber = OptionalLong.of(blockNumber);
return this;
}

public StubGenesisConfigOptions phoenix(final long blockNumber) {
phoenixBlockNumber = OptionalLong.of(blockNumber);
return this;
}

public StubGenesisConfigOptions thanos(final long blockNumber) {
thanosBlockNumber = OptionalLong.of(blockNumber);
return this;
}

public StubGenesisConfigOptions ecip1049(final long blockNumber) {
ecip1049BlockNumber = OptionalLong.of(blockNumber);
return this;
}

public StubGenesisConfigOptions chainId(final BigInteger chainId) {
this.chainId = Optional.ofNullable(chainId);
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.hyperledger.besu.ethereum.mainnet.MainnetProtocolSpecs;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
import org.hyperledger.besu.ethereum.mainnet.ProtocolScheduleBuilder;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSpecAdapters;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSpecBuilder;

import java.math.BigInteger;
Expand Down Expand Up @@ -64,14 +65,16 @@ public static ProtocolSchedule create(
return new ProtocolScheduleBuilder(
config,
DEFAULT_CHAIN_ID,
builder ->
applyCliqueSpecificModifications(
epochManager,
cliqueConfig.getBlockPeriodSeconds(),
localNodeAddress,
builder,
eip1559,
privacyParameters.getGoQuorumPrivacyParameters().isPresent()),
ProtocolSpecAdapters.create(
0,
builder ->
applyCliqueSpecificModifications(
epochManager,
cliqueConfig.getBlockPeriodSeconds(),
localNodeAddress,
builder,
eip1559,
privacyParameters.getGoQuorumPrivacyParameters().isPresent())),
privacyParameters,
isRevertReasonEnabled,
config.isQuorum())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.hyperledger.besu.ethereum.mainnet.MainnetProtocolSpecs;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
import org.hyperledger.besu.ethereum.mainnet.ProtocolScheduleBuilder;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSpecAdapters;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSpecBuilder;

import java.math.BigInteger;
Expand All @@ -44,9 +45,14 @@ public static ProtocolSchedule create(
return new ProtocolScheduleBuilder(
config,
DEFAULT_CHAIN_ID,
builder ->
applyBftChanges(
config.getBftConfigOptions(), builder, config.isQuorum(), blockHeaderRuleset),
ProtocolSpecAdapters.create(
0,
builder ->
applyBftChanges(
config.getBftConfigOptions(),
builder,
config.isQuorum(),
blockHeaderRuleset)),
privacyParameters,
isRevertReasonEnabled,
config.isQuorum())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.hyperledger.besu.ethereum.mainnet.MainnetProtocolSpecs;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
import org.hyperledger.besu.ethereum.mainnet.ProtocolScheduleBuilder;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSpecAdapters;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSpecBuilder;

import java.math.BigInteger;
Expand All @@ -44,9 +45,11 @@ public static ProtocolSchedule create(
return new ProtocolScheduleBuilder(
config,
DEFAULT_CHAIN_ID,
builder ->
applyIbftChanges(
blockPeriod, builder, config.isQuorum(), ibftConfig.getCeil2Nby3Block()),
ProtocolSpecAdapters.create(
0,
builder ->
applyIbftChanges(
blockPeriod, builder, config.isQuorum(), ibftConfig.getCeil2Nby3Block())),
privacyParameters,
isRevertReasonEnabled,
config.isQuorum())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import static com.google.common.base.Preconditions.checkArgument;

import org.hyperledger.besu.ethereum.api.graphql.internal.pojoadapter.AccountAdapter;
import org.hyperledger.besu.ethereum.api.graphql.internal.pojoadapter.EmptyAccountAdapter;
import org.hyperledger.besu.ethereum.api.graphql.internal.pojoadapter.LogAdapter;
import org.hyperledger.besu.ethereum.api.graphql.internal.pojoadapter.NormalBlockAdapter;
import org.hyperledger.besu.ethereum.api.graphql.internal.pojoadapter.PendingStateAdapter;
Expand Down Expand Up @@ -186,8 +187,9 @@ DataFetcher<Optional<AccountAdapter>> getAccountDataFetcher() {
final Optional<WorldState> ws = blockchainQuery.getWorldState(bn);
if (ws.isPresent()) {
final Account account = ws.get().get(addr);
Preconditions.checkArgument(
account != null, "Account with address %s does not exist", addr);
if (account == null) {
return Optional.of(new EmptyAccountAdapter(addr));
}
return Optional.of(new AccountAdapter(account));
} else if (bn > blockchainQuery.getBlockchain().getChainHeadBlockNumber()) {
// block is past chainhead
Expand All @@ -201,13 +203,13 @@ DataFetcher<Optional<AccountAdapter>> getAccountDataFetcher() {
final long latestBn = blockchainQuery.latestBlock().get().getHeader().getNumber();
final Optional<WorldState> ows = blockchainQuery.getWorldState(latestBn);
return ows.flatMap(
ws -> {
Account account = ws.get(addr);
Preconditions.checkArgument(
account != null, "Account with address %s does not exist", addr);
return Optional.ofNullable(account);
})
.map(AccountAdapter::new);
ws -> {
Account account = ws.get(addr);
if (account == null) {
return Optional.of(new EmptyAccountAdapter(addr));
}
return Optional.of(new AccountAdapter(account));
});
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,30 +23,35 @@
import org.apache.tuweni.bytes.Bytes;
import org.apache.tuweni.bytes.Bytes32;

@SuppressWarnings("unused") // reflected by GraphQL
public class EmptyAccountAdapter extends AdapterBase {
public class EmptyAccountAdapter extends AccountAdapter {
private final Address address;

public EmptyAccountAdapter(final Address address) {
super(null);
this.address = address;
}

@Override
public Optional<Address> getAddress() {
return Optional.of(address);
}

@Override
public Optional<Wei> getBalance() {
return Optional.of(Wei.ZERO);
}

@Override
public Optional<Long> getTransactionCount() {
return Optional.of(0L);
}

@Override
public Optional<Bytes> getCode() {
return Optional.of(Bytes.EMPTY);
}

@Override
public Optional<Bytes32> getStorage(final DataFetchingEnvironment environment) {
return Optional.of(Bytes32.ZERO);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public Optional<Long> getCumulativeGasUsed(final DataFetchingEnvironment environ
public Optional<AccountAdapter> getCreatedContract(final DataFetchingEnvironment environment) {
final boolean contractCreated = transactionWithMetadata.getTransaction().isContractCreation();
if (contractCreated) {
final Optional<Address> addr = transactionWithMetadata.getTransaction().getTo();
final Optional<Address> addr = transactionWithMetadata.getTransaction().contractAddress();

if (addr.isPresent()) {
final BlockchainQueries query = getBlockchainQueries(environment);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,62 @@ public void returnsErrorWhenP2PNotReady() {
assertThat(response).isEqualToComparingFieldByField(expectedResponse);
}

@SuppressWarnings("unchecked")
@Test
public void returnsClassicForkBlocks() {
when(p2pNetwork.isP2pEnabled()).thenReturn(true);
when(p2pNetwork.getLocalEnode()).thenReturn(Optional.of(defaultPeer.getEnodeURL()));
final GenesisConfigOptions genesisClassicConfigOptions =
new StubGenesisConfigOptions()
.chainId(BigInteger.valueOf(2019))
.classicForkBlock(1)
.ecip1015(2)
.dieHard(3)
.gotham(4)
.defuseDifficultyBomb(5)
.atlantis(6)
.agharta(7)
.phoenix(8)
.thanos(9)
.ecip1049(10);

final AdminNodeInfo methodClassic =
new AdminNodeInfo(
"testnetClassic/1.0/this/that",
BigInteger.valueOf(2018),
genesisClassicConfigOptions,
p2pNetwork,
blockchainQueries,
natService);

final JsonRpcRequestContext request = adminNodeInfo();

final Map<String, Long> expectedConfig =
Map.of(
"classicForkBlock", 1L,
"ecip1015Block", 2L,
"dieHardBlock", 3L,
"gothamBlock", 4L,
"ecip1041Block", 5L,
"atlantisBlock", 6L,
"aghartaBlock", 7L,
"phoenixBlock", 8L,
"thanosBlock", 9L,
"ecip1049Block", 10L);

final JsonRpcResponse response = methodClassic.response(request);
assertThat(response).isInstanceOf(JsonRpcSuccessResponse.class);
final Object result = ((JsonRpcSuccessResponse) response).getResult();
assertThat(result).isInstanceOf(Map.class);
final Object protocolsMap = ((Map<?, ?>) result).get("protocols");
assertThat(protocolsMap).isInstanceOf(Map.class);
final Object ethMap = ((Map<?, ?>) protocolsMap).get("eth");
assertThat(ethMap).isInstanceOf(Map.class);
final Object configMap = ((Map<?, ?>) ethMap).get("config");
assertThat(configMap).isInstanceOf(Map.class);
assertThat(((Map<String, Long>) configMap)).containsAllEntriesOf(expectedConfig);
}

private JsonRpcRequestContext adminNodeInfo() {
return new JsonRpcRequestContext(new JsonRpcRequest("2.0", "admin_nodeInfo", new Object[] {}));
}
Expand Down
Loading

0 comments on commit 7d9acd0

Please sign in to comment.