|
13 | 13 | import io.optimism.engine.OpEthExecutionPayload;
|
14 | 14 | import io.optimism.engine.OpEthForkChoiceUpdate;
|
15 | 15 | import io.optimism.engine.OpEthPayloadStatus;
|
| 16 | +import io.optimism.network.ExecutionPayloadEnvelop; |
16 | 17 | import io.optimism.type.Epoch;
|
17 | 18 | import io.optimism.type.L2BlockRef;
|
| 19 | +import io.optimism.type.PayloadInfo; |
| 20 | +import io.optimism.type.enums.BlockInsertion; |
18 | 21 | import io.optimism.type.enums.SyncStatus;
|
19 | 22 | import io.optimism.utilities.telemetry.TracerTaskWrapper;
|
20 | 23 | import java.math.BigInteger;
|
|
31 | 34 | import org.web3j.protocol.core.DefaultBlockParameterName;
|
32 | 35 | import org.web3j.protocol.core.methods.response.EthBlock;
|
33 | 36 | import org.web3j.protocol.core.methods.response.EthBlock.TransactionObject;
|
| 37 | +import org.web3j.tuples.generated.Tuple2; |
| 38 | +import org.web3j.tuples.generated.Tuple3; |
| 39 | +import org.web3j.utils.Numeric; |
34 | 40 |
|
35 | 41 | /**
|
36 | 42 | * The type EngineDriver.
|
@@ -63,6 +69,13 @@ public class EngineDriver<E extends Engine> {
|
63 | 69 | private Epoch finalizedEpoch;
|
64 | 70 |
|
65 | 71 | private SyncStatus syncStatus;
|
| 72 | + |
| 73 | + // building state |
| 74 | + private L2BlockRef buildingOnto; |
| 75 | + private PayloadInfo buildingInfo; |
| 76 | + private boolean buildingSafe; |
| 77 | + private PayloadAttributes safeAttrs; |
| 78 | + |
66 | 79 | /**
|
67 | 80 | * Instantiates a new Engine driver.
|
68 | 81 | *
|
@@ -223,6 +236,69 @@ public void handleUnsafePayload(ExecutionPayload payload) throws ExecutionExcept
|
223 | 236 | }
|
224 | 237 | }
|
225 | 238 |
|
| 239 | + /** |
| 240 | + * Start building payload block insertion. |
| 241 | + * |
| 242 | + * @param parent the parent |
| 243 | + * @param attributes the attributes |
| 244 | + * @return the block insertion |
| 245 | + */ |
| 246 | + public BlockInsertion startBuildingPayload(L2BlockRef parent, PayloadAttributes attributes) { |
| 247 | + if (this.isEngineSyncing()) { |
| 248 | + return BlockInsertion.TEMPORARY; |
| 249 | + } |
| 250 | + return BlockInsertion.SUCCESS; |
| 251 | + } |
| 252 | + |
| 253 | + /** |
| 254 | + * Confirm building payload. |
| 255 | + * |
| 256 | + * @return ExecutionPayloadEnvelop and insertion status |
| 257 | + */ |
| 258 | + public Tuple2<ExecutionPayloadEnvelop, BlockInsertion> confirmBuildingPayload() { |
| 259 | + return null; |
| 260 | + } |
| 261 | + |
| 262 | + /** |
| 263 | + * Cancel building payload. |
| 264 | + * @param force if true then reset building state forcefully, otherwise throw exception |
| 265 | + */ |
| 266 | + public void cancelPayload(boolean force) { |
| 267 | + if (this.buildingInfo == null) { |
| 268 | + return; |
| 269 | + } |
| 270 | + // e.log.Error("cancelling old block sealing job", "payload", e.buildingInfo.ID) |
| 271 | + LOGGER.error("cancelling old block sealing job: payload = {}", this.buildingInfo.payloadId()); |
| 272 | + try { |
| 273 | + this.engine.getPayload(this.buildingInfo.timestamp(), Numeric.toBigInt(this.buildingInfo.payloadId())); |
| 274 | + } catch (Exception e) { |
| 275 | + if (!force) { |
| 276 | + throw new RuntimeException(e); |
| 277 | + } |
| 278 | + LOGGER.error("failed to cancel block building job: payload = {}", this.buildingInfo.payloadId(), e); |
| 279 | + } |
| 280 | + this.resetBuildingState(); |
| 281 | + } |
| 282 | + |
| 283 | + /** |
| 284 | + * Reset building state. |
| 285 | + */ |
| 286 | + public void resetBuildingState() { |
| 287 | + this.buildingInfo = null; |
| 288 | + this.buildingOnto = null; |
| 289 | + this.buildingSafe = false; |
| 290 | + this.safeAttrs = null; |
| 291 | + } |
| 292 | + |
| 293 | + /** |
| 294 | + * Gets building payload info. |
| 295 | + * |
| 296 | + * @return the building payload |
| 297 | + */ |
| 298 | + public Tuple3<L2BlockRef, String, Boolean> buildingPayload() { |
| 299 | + return new Tuple3<>(buildingOnto, buildingInfo.payloadId(), buildingSafe); |
| 300 | + } |
| 301 | + |
226 | 302 | /**
|
227 | 303 | * Update finalized.
|
228 | 304 | *
|
|
0 commit comments