Skip to content

Commit 012577e

Browse files
avaloncheCopilot
andauthored
Add flashtestations integration tests (#283)
* Add flashtestation builder tx and registration in block * copilot comments * Add flashtestations integration tests * logging improvements * Update crates/op-rbuilder/src/tests/flashtestations.rs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 5cd19de commit 012577e

File tree

13 files changed

+717
-37
lines changed

13 files changed

+717
-37
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ This will increment the flashblock number before the start of every flashblock a
6363
To run op-rbuilder with flashtestations:
6464

6565
```bash
66-
cargo run -p op-rbuilder --bin op-rbuilder --features=flashtestations -- node \
66+
cargo run -p op-rbuilder --bin op-rbuilder -- node \
6767
--chain /path/to/chain-config.json \
6868
--http \
6969
--authrpc.port 9551 \
@@ -73,7 +73,7 @@ cargo run -p op-rbuilder --bin op-rbuilder --features=flashtestations -- node \
7373
--flashtestations.funding-amount 0.01 \ # amount in ETH to fund the TEE generated key
7474
--flashtestations.funding-key secret-key \ # funding key for the TEE key
7575
--flashtestations.registry-address 0xFlashtestationsRegistryAddress \
76-
flashtestations.builder-policy-address 0xBuilderPolicyAddress
76+
--flashtestations.builder-policy-address 0xBuilderPolicyAddress
7777
```
7878

7979
Note that `--rollup.builder-secret-key` must be set and funded in order for the flashtestations key to be funded and submit the attestation on-chain.

crates/op-rbuilder/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,9 @@ testing = [
192192
"ctor",
193193
"macros",
194194
"rlimit",
195+
"hyper",
196+
"hyper-util",
197+
"http-body-util",
195198
]
196199

197200
interop = []

crates/op-rbuilder/src/flashtestations/attestation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ impl RemoteAttestationProvider {
3333
let report_data_hex = hex::encode(report_data);
3434
let url = format!("{}/{}", self.service_url, report_data_hex);
3535

36-
info!(target: "flashtestations", url = url, "fetching quote in debug mode");
36+
info!(target: "flashtestations", url = url, "fetching quote from remote attestation provider");
3737

3838
let response = self
3939
.client

crates/op-rbuilder/src/flashtestations/builder_tx.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use revm::{
1717
inspector::NoOpInspector,
1818
state::Account,
1919
};
20-
use std::sync::OnceLock;
20+
use std::sync::{Arc, atomic::AtomicBool};
2121
use tracing::{debug, info};
2222

2323
use crate::{
@@ -66,7 +66,7 @@ pub struct FlashtestationsBuilderTx {
6666
// Builder proof version
6767
builder_proof_version: u8,
6868
// Whether the workload and address has been registered
69-
registered: OnceLock<bool>,
69+
registered: Arc<AtomicBool>,
7070
// Whether block proofs are enabled
7171
enable_block_proofs: bool,
7272
}
@@ -91,7 +91,7 @@ impl FlashtestationsBuilderTx {
9191
registry_address: args.registry_address,
9292
builder_policy_address: args.builder_policy_address,
9393
builder_proof_version: args.builder_proof_version,
94-
registered: OnceLock::new(),
94+
registered: Arc::new(AtomicBool::new(args.registered)),
9595
enable_block_proofs: args.enable_block_proofs,
9696
}
9797
}
@@ -178,7 +178,7 @@ impl FlashtestationsBuilderTx {
178178
/// keccak256(abi.encode(parentHash, blockNumber, timestamp, transactionHashes))
179179
/// https://github.com/flashbots/rollup-boost/blob/main/specs/flashtestations.md#block-building-process
180180
fn compute_block_content_hash(
181-
transactions: Vec<OpTransactionSigned>,
181+
transactions: &[OpTransactionSigned],
182182
parent_hash: B256,
183183
block_number: u64,
184184
timestamp: u64,
@@ -475,7 +475,7 @@ impl FlashtestationsBuilderTx {
475475
>,
476476
) -> Result<Option<BuilderTransactionCtx>, BuilderTransactionError> {
477477
let block_content_hash = Self::compute_block_content_hash(
478-
transactions.clone(),
478+
&transactions,
479479
ctx.parent_hash(),
480480
ctx.block_number(),
481481
ctx.timestamp(),
@@ -545,11 +545,12 @@ impl FlashtestationsBuilderTx {
545545
match self.register_tee_service_tx(ctx, &mut evm) {
546546
Ok((_, registered)) => {
547547
if registered {
548-
let _ = self.registered.set(registered);
548+
self.registered
549+
.store(true, std::sync::atomic::Ordering::SeqCst);
549550
}
550551
Ok(())
551552
}
552-
Err(e) => Err(BuilderTransactionError::other(e)),
553+
Err(e) => Err(e),
553554
}
554555
}
555556
}
@@ -563,7 +564,7 @@ impl<ExtraCtx: Debug + Default> BuilderTransactions<ExtraCtx> for Flashtestation
563564
db: &mut State<impl Database>,
564565
) -> Result<Vec<BuilderTransactionCtx>, BuilderTransactionError> {
565566
// set registered simulating against the committed state
566-
if !self.registered.get().unwrap_or(&false) {
567+
if !self.registered.load(std::sync::atomic::Ordering::SeqCst) {
567568
self.set_registered(state_provider.clone(), ctx)?;
568569
}
569570

@@ -583,7 +584,7 @@ impl<ExtraCtx: Debug + Default> BuilderTransactions<ExtraCtx> for Flashtestation
583584

584585
let mut builder_txs = Vec::<BuilderTransactionCtx>::new();
585586

586-
if !self.registered.get().unwrap_or(&false) {
587+
if !self.registered.load(std::sync::atomic::Ordering::SeqCst) {
587588
info!(target: "flashtestations", "tee service not registered yet, attempting to register");
588589
builder_txs.extend(self.fund_tee_service_tx(ctx, &mut evm)?);
589590
let (register_tx, _) = self.register_tee_service_tx(ctx, &mut evm)?;

crates/op-rbuilder/src/tests/flashblocks.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,19 @@
11
use alloy_consensus::Transaction;
22
use alloy_eips::Decodable2718;
3-
use alloy_primitives::{Address, TxHash, U256, address, b128, b256};
3+
use alloy_primitives::{Address, TxHash, U256};
44
use alloy_provider::Provider;
5-
use alloy_sol_types::SolCall;
65
use macros::rb_test;
76
use op_alloy_consensus::OpTxEnvelope;
87
use std::time::Duration;
98

109
use crate::{
1110
args::{FlashblocksArgs, OpRbuilderArgs},
1211
tests::{
13-
BUILDER_PRIVATE_KEY, BlockTransactionsExt, BundleOpts, ChainDriver, ChainDriverExt,
14-
FUNDED_PRIVATE_KEY, LocalInstance, ONE_ETH, TransactionBuilderExt,
15-
flashblocks_number_contract::FlashblocksNumber,
12+
BlockTransactionsExt, BundleOpts, ChainDriver, FLASHBLOCKS_NUMBER_ADDRESS, LocalInstance,
13+
TransactionBuilderExt, flashblocks_number_contract::FlashblocksNumber,
1614
},
17-
tx_signer::Signer,
1815
};
1916

20-
// If the order of deployment from the signer changes the address will change
21-
const FLASHBLOCKS_NUMBER_ADDRESS: Address = address!("5fbdb2315678afecb367f032d93f642f64180aa3");
22-
2317
#[rb_test(flashblocks, args = OpRbuilderArgs {
2418
chain_block_time: 2000,
2519
flashblocks: FlashblocksArgs {

0 commit comments

Comments
 (0)