forked from hyperledger/besu
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MERGE: engine_exchangeTransitionConfigurationV1 API (hyperledger#3473)
Signed-off-by: Daniel Lehrner <[email protected]> Signed-off-by: garyschulte <[email protected]>
- Loading branch information
1 parent
6efdd94
commit 424ed9c
Showing
6 changed files
with
451 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
117 changes: 117 additions & 0 deletions
117
...u/ethereum/api/jsonrpc/internal/methods/engine/EngineExchangeTransitionConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
/* | ||
* Copyright Hyperledger Besu Contributors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.engine; | ||
|
||
import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcError.INVALID_PARAMS; | ||
import static org.hyperledger.besu.util.Slf4jLambdaHelper.traceLambda; | ||
|
||
import org.hyperledger.besu.datatypes.Hash; | ||
import org.hyperledger.besu.ethereum.ProtocolContext; | ||
import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod; | ||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext; | ||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.ExecutionEngineJsonRpcMethod; | ||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.EngineExchangeTransitionConfigurationParameter; | ||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcError; | ||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse; | ||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse; | ||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse; | ||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.EngineExchangeTransitionConfigurationResult; | ||
import org.hyperledger.besu.ethereum.core.BlockHeader; | ||
|
||
import java.util.Optional; | ||
|
||
import io.vertx.core.Vertx; | ||
import io.vertx.core.json.Json; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class EngineExchangeTransitionConfiguration extends ExecutionEngineJsonRpcMethod { | ||
private static final Logger LOG = | ||
LoggerFactory.getLogger(EngineExchangeTransitionConfiguration.class); | ||
|
||
public EngineExchangeTransitionConfiguration( | ||
final Vertx vertx, final ProtocolContext protocolContext) { | ||
super(vertx, protocolContext); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return RpcMethod.ENGINE_EXCHANGE_TRANSITION_CONFIGURATION.getMethodName(); | ||
} | ||
|
||
@Override | ||
public JsonRpcResponse syncResponse(final JsonRpcRequestContext requestContext) { | ||
final EngineExchangeTransitionConfigurationParameter remoteTransitionConfiguration = | ||
requestContext.getRequiredParameter( | ||
0, EngineExchangeTransitionConfigurationParameter.class); | ||
final Object reqId = requestContext.getRequest().getId(); | ||
|
||
traceLambda( | ||
LOG, | ||
"received transitionConfiguration: {}", | ||
() -> Json.encodePrettily(remoteTransitionConfiguration)); | ||
|
||
if (remoteTransitionConfiguration.getTerminalBlockNumber() != 0L) { | ||
return respondWithError(reqId, INVALID_PARAMS); | ||
} | ||
|
||
final Optional<BlockHeader> maybeTerminalPoWBlockHeader = mergeContext.getTerminalPoWBlock(); | ||
|
||
final EngineExchangeTransitionConfigurationResult localTransitionConfiguration = | ||
new EngineExchangeTransitionConfigurationResult( | ||
mergeContext.getTerminalTotalDifficulty(), | ||
maybeTerminalPoWBlockHeader.map(BlockHeader::getHash).orElse(Hash.ZERO), | ||
maybeTerminalPoWBlockHeader.map(BlockHeader::getNumber).orElse(0L)); | ||
|
||
if (!localTransitionConfiguration | ||
.getTerminalTotalDifficulty() | ||
.equals(remoteTransitionConfiguration.getTerminalTotalDifficulty())) { | ||
LOG.warn( | ||
"Configured terminal total difficulty {} does not match value of consensus client {}", | ||
localTransitionConfiguration.getTerminalTotalDifficulty(), | ||
remoteTransitionConfiguration.getTerminalTotalDifficulty()); | ||
} | ||
|
||
if (!localTransitionConfiguration | ||
.getTerminalBlockHash() | ||
.equals(remoteTransitionConfiguration.getTerminalBlockHash())) { | ||
LOG.warn( | ||
"Configured terminal block hash {} does not match value of consensus client {}", | ||
localTransitionConfiguration.getTerminalBlockHash(), | ||
remoteTransitionConfiguration.getTerminalBlockHash()); | ||
} | ||
|
||
if (localTransitionConfiguration.getTerminalBlockNumber() | ||
!= remoteTransitionConfiguration.getTerminalBlockNumber()) { | ||
LOG.debug( | ||
"Configured terminal block number {} does not match value of consensus client {}", | ||
localTransitionConfiguration.getTerminalBlockNumber(), | ||
remoteTransitionConfiguration.getTerminalBlockNumber()); | ||
} | ||
|
||
return respondWith(reqId, localTransitionConfiguration); | ||
} | ||
|
||
private JsonRpcResponse respondWith( | ||
final Object requestId, | ||
final EngineExchangeTransitionConfigurationResult transitionConfiguration) { | ||
return new JsonRpcSuccessResponse(requestId, transitionConfiguration); | ||
} | ||
|
||
private JsonRpcResponse respondWithError( | ||
final Object requestId, final JsonRpcError jsonRpcError) { | ||
return new JsonRpcErrorResponse(requestId, jsonRpcError); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
...ereum/api/jsonrpc/internal/parameters/EngineExchangeTransitionConfigurationParameter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright Hyperledger Besu Contributors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters; | ||
|
||
import org.hyperledger.besu.datatypes.Hash; | ||
import org.hyperledger.besu.ethereum.core.Difficulty; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
public class EngineExchangeTransitionConfigurationParameter { | ||
private final Difficulty terminalTotalDifficulty; | ||
private final Hash terminalBlockHash; | ||
private final long terminalBlockNumber; | ||
|
||
@JsonCreator | ||
public EngineExchangeTransitionConfigurationParameter( | ||
@JsonProperty("terminalTotalDifficulty") final String terminalTotalDifficulty, | ||
@JsonProperty("terminalBlockHash") final String terminalBlockHash, | ||
@JsonProperty("terminalBlockNumber") final UnsignedLongParameter terminalBlockNumber) { | ||
this.terminalTotalDifficulty = Difficulty.fromHexString(terminalTotalDifficulty); | ||
this.terminalBlockHash = Hash.fromHexString(terminalBlockHash); | ||
this.terminalBlockNumber = terminalBlockNumber.getValue(); | ||
} | ||
|
||
public Difficulty getTerminalTotalDifficulty() { | ||
return terminalTotalDifficulty; | ||
} | ||
|
||
public Hash getTerminalBlockHash() { | ||
return terminalBlockHash; | ||
} | ||
|
||
public long getTerminalBlockNumber() { | ||
return terminalBlockNumber; | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
...su/ethereum/api/jsonrpc/internal/results/EngineExchangeTransitionConfigurationResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* Copyright Hyperledger Besu Contributors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package org.hyperledger.besu.ethereum.api.jsonrpc.internal.results; | ||
|
||
import org.hyperledger.besu.datatypes.Hash; | ||
import org.hyperledger.besu.ethereum.core.Difficulty; | ||
|
||
import java.util.Optional; | ||
|
||
import com.fasterxml.jackson.annotation.JsonGetter; | ||
import com.fasterxml.jackson.annotation.JsonPropertyOrder; | ||
|
||
@JsonPropertyOrder({"terminalTotalDifficulty", "terminalBlockHash", "terminalBlockNumber"}) | ||
public class EngineExchangeTransitionConfigurationResult { | ||
private final Difficulty terminalTotalDifficulty; | ||
private final Hash terminalBlockHash; | ||
private final long terminalBlockNumber; | ||
|
||
public EngineExchangeTransitionConfigurationResult( | ||
final Difficulty terminalTotalDifficulty, | ||
final Hash terminalBlockHash, | ||
final long terminalBlockNumber) { | ||
this.terminalTotalDifficulty = terminalTotalDifficulty; | ||
this.terminalBlockHash = terminalBlockHash; | ||
this.terminalBlockNumber = terminalBlockNumber; | ||
} | ||
|
||
@JsonGetter(value = "terminalTotalDifficulty") | ||
public String getTerminalTotalDifficultyAsString() { | ||
return terminalTotalDifficulty.toHexString(); | ||
} | ||
|
||
public Difficulty getTerminalTotalDifficulty() { | ||
return terminalTotalDifficulty; | ||
} | ||
|
||
@JsonGetter(value = "terminalBlockHash") | ||
public String getTerminalBlockHashAsString() { | ||
return terminalBlockHash.toHexString(); | ||
} | ||
|
||
public Hash getTerminalBlockHash() { | ||
return terminalBlockHash; | ||
} | ||
|
||
@JsonGetter(value = "terminalBlockNumber") | ||
public String getTerminalBlockNumberAsString() { | ||
return Optional.of(terminalBlockNumber) | ||
.filter(val -> val != 0L) | ||
.map(Long::toHexString) | ||
.orElse("0x0"); | ||
} | ||
|
||
public Long getTerminalBlockNumber() { | ||
return terminalBlockNumber; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.