Skip to content

Commit

Permalink
seperating optimistic sync, fixing and testing the transaction submis…
Browse files Browse the repository at this point in the history
…sion/execution
  • Loading branch information
g11tech committed Nov 15, 2021
1 parent a1c6635 commit c15bf07
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 23 deletions.
26 changes: 12 additions & 14 deletions packages/fork-choice/src/forkChoice/forkChoice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -920,19 +920,17 @@ function assertValidTerminalPowBlock(
block.body.executionPayload.parentHash
)}`
);

// TERMINAL_BLOCK_HASH override skips ttd checks
return;
} else {
// If no TERMINAL_BLOCK_HASH override, check ttd
const {powBlock, powBlockParent} = preCachedData || {};
if (!powBlock) throw Error("onBlock preCachedData must include powBlock");
if (!powBlockParent) throw Error("onBlock preCachedData must include powBlock");

const isTotalDifficultyReached = powBlock.totalDifficulty >= config.TERMINAL_TOTAL_DIFFICULTY;
const isParentTotalDifficultyValid = powBlockParent.totalDifficulty < config.TERMINAL_TOTAL_DIFFICULTY;
if (!isTotalDifficultyReached || !isParentTotalDifficultyValid)
throw Error(
`Invalid terminal POW block: total difficulty not reached ${powBlockParent.totalDifficulty} < ${powBlock.totalDifficulty}`
);
}

const {powBlock, powBlockParent} = preCachedData || {};
if (!powBlock) throw Error("onBlock preCachedData must include powBlock");
if (!powBlockParent) throw Error("onBlock preCachedData must include powBlock");

const isTotalDifficultyReached = powBlock.totalDifficulty >= config.TERMINAL_TOTAL_DIFFICULTY;
const isParentTotalDifficultyValid = powBlockParent.totalDifficulty < config.TERMINAL_TOTAL_DIFFICULTY;
if (!isTotalDifficultyReached || !isParentTotalDifficultyValid)
throw Error(
`Invalid terminal POW block: total difficulty not reached ${powBlockParent.totalDifficulty} < ${powBlock.totalDifficulty}`
);
}
4 changes: 2 additions & 2 deletions packages/lodestar/src/executionEngine/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ export function serializeExecutionPayload(data: merge.ExecutionPayload): Executi
extraData: bytesToData(data.extraData),
baseFeePerGas: numToQuantity(data.baseFeePerGas),
blockHash: bytesToData(data.blockHash),
transactions: data.transactions.map((tran) => bytesToData(tran.value)),
transactions: data.transactions.map((tran) => bytesToData(tran)),
};
}

Expand All @@ -240,6 +240,6 @@ export function parseExecutionPayload(data: ExecutionPayloadRpc): merge.Executio
extraData: dataToBytes(data.extraData),
baseFeePerGas: quantityToBigint(data.baseFeePerGas),
blockHash: dataToBytes(data.blockHash, 32),
transactions: data.transactions.map((tran) => ({selector: 0, value: dataToBytes(tran)})),
transactions: data.transactions.map((tran) => dataToBytes(tran)),
};
}
2 changes: 1 addition & 1 deletion packages/lodestar/src/executionEngine/mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export class ExecutionEngineMock implements IExecutionEngine {
extraData: ZERO_HASH,
baseFeePerGas: BigInt(0),
blockHash: crypto.randomBytes(32),
transactions: [{selector: 0, value: crypto.randomBytes(512)}],
transactions: [crypto.randomBytes(512)],
};
this.preparingPayloads.set(payloadId, payload);

Expand Down
7 changes: 1 addition & 6 deletions packages/types/src/merge/types.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import * as altair from "../altair/types";
import {Root, Bytes32, Number64, ExecutionAddress, Uint256} from "../primitive/types";

export type OpaqueTransaction = Uint8Array;

export type Transaction = {
selector: number;
value: OpaqueTransaction;
};
export type Transaction = Uint8Array;

type ExecutionPayloadFields = {
// Execution block header fields
Expand Down

0 comments on commit c15bf07

Please sign in to comment.