Skip to content

refactor: remove unsupported bridge modes #1758

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 15, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,6 @@ jobs:
steps:
- checkout
- setup_remote_docker
- run:
name: Clone portal-accumulators
command: git clone https://github.com/ethereum/portal-accumulators
- run:
name: Build Docker bridge image
no_output_timeout: 30m
Expand Down
3 changes: 0 additions & 3 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,3 @@

# include for vergen constants
!/.git

# include portal-accumulators, which is used in the portal-bridge Dockerfile
!/portal-accumulators
2 changes: 0 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ rust-version = "1.85.0"
version = "0.2.1"

[workspace.dependencies]
alloy = { version = "0.12", default-features = false, features = ["std"] }
alloy = { version = "0.12", default-features = false, features = ["std", "serde"] }
alloy-rlp = { version = "0.3.8", default-features = false, features = ["derive"] }
anyhow = "1.0.68"
async-trait = "0.1.68"
Expand Down
4 changes: 3 additions & 1 deletion bin/e2hs-writer/src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use std::path::PathBuf;

use clap::Parser;
use portal_bridge::{cli::DEFAULT_EPOCH_ACC_PATH, DEFAULT_BASE_EL_ENDPOINT};
use portal_bridge::DEFAULT_BASE_EL_ENDPOINT;
use url::Url;

pub const DEFAULT_EPOCH_ACC_PATH: &str = "./portal-accumulators";

#[derive(Parser, Debug, Clone)]
#[command(name = "E2HS Writer", about = "Generate E2HS files")]
pub struct WriterConfig {
Expand Down
7 changes: 5 additions & 2 deletions bin/e2hs-writer/src/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use ethportal_api::types::{
},
};
use futures::Stream;
use portal_bridge::{api::execution::ExecutionApi, bridge::utils::lookup_epoch_acc};
use portal_bridge::api::execution::ExecutionApi;
use ssz_types::{typenum, FixedVector, VariableList};
use tokio::try_join;
use tree_hash::TreeHash;
Expand All @@ -35,7 +35,10 @@ use url::Url;

use crate::{
provider::EraProvider,
utils::{pre_capella_execution_payload_to_header, pre_deneb_execution_payload_to_header},
utils::{
lookup_epoch_acc, pre_capella_execution_payload_to_header,
pre_deneb_execution_payload_to_header,
},
};

pub struct AllBlockData {
Expand Down
38 changes: 35 additions & 3 deletions bin/e2hs-writer/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::{fs, path::Path};

use alloy::{
consensus::{
proofs::{calculate_transaction_root, calculate_withdrawals_root},
Expand All @@ -6,11 +8,17 @@ use alloy::{
eips::eip4895::Withdrawal,
primitives::{Bloom, B64, U256},
};
use anyhow::ensure;
use ethportal_api::types::consensus::execution_payload::{
ExecutionPayloadBellatrix, ExecutionPayloadCapella,
use anyhow::{anyhow, ensure};
use ethportal_api::{
types::{
consensus::execution_payload::{ExecutionPayloadBellatrix, ExecutionPayloadCapella},
execution::accumulator::EpochAccumulator,
},
utils::bytes::hex_encode,
};
use ssz::Decode;
use trin_execution::era::beacon::EMPTY_UNCLE_ROOT_HASH;
use trin_validation::accumulator::PreMergeAccumulator;

pub fn pre_capella_execution_payload_to_header(
payload: ExecutionPayloadBellatrix,
Expand Down Expand Up @@ -85,3 +93,27 @@ pub fn pre_deneb_execution_payload_to_header(
);
Ok(header)
}

/// Lookup the epoch accumulator & epoch hash for the given epoch index.
pub async fn lookup_epoch_acc(
epoch_index: u64,
pre_merge_acc: &PreMergeAccumulator,
epoch_acc_path: &Path,
) -> anyhow::Result<EpochAccumulator> {
let epoch_hash = pre_merge_acc.historical_epochs[epoch_index as usize];
let epoch_hash_pretty = hex_encode(epoch_hash);
let epoch_hash_pretty = epoch_hash_pretty.trim_start_matches("0x");
let epoch_acc_path = format!(
"{}/bridge_content/0x03{epoch_hash_pretty}.portalcontent",
epoch_acc_path.display(),
);
let epoch_acc = match fs::read(&epoch_acc_path) {
Ok(val) => EpochAccumulator::from_ssz_bytes(&val).map_err(|err| anyhow!("{err:?}"))?,
Err(_) => {
return Err(anyhow!(
"Unable to find local epoch acc at path: {epoch_acc_path:?}"
))
}
};
Ok(epoch_acc)
}
2 changes: 0 additions & 2 deletions bin/portal-bridge/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,12 @@ version.workspace = true
[dependencies]
alloy.workspace = true
anyhow.workspace = true
async-trait.workspace = true
chrono.workspace = true
clap.workspace = true
delay_map.workspace = true
discv5.workspace = true
e2store.workspace = true
eth_trie.workspace = true
ethereum_ssz.workspace = true
ethportal-api.workspace = true
futures.workspace = true
humanize-duration.workspace = true
Expand Down
28 changes: 3 additions & 25 deletions bin/portal-bridge/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ Process to feed the portal network by gossiping data retrieved from a trusted pr

ex.
```sh
git clone https://github.com/ethereum/portal-accumulators.git
cargo run -p portal-bridge -- --executable-path ./target/debug/trin --epoch-accumulator-path ./portal-accumulators
cargo run -p portal-bridge -- --executable-path ./target/debug/trin
```

## Providers
Expand All @@ -25,27 +24,7 @@ cargo run -p portal-bridge -- --executable-path ./target/debug/trin --epoch-accu

### Bridge modes

#### History Subnetwork

- `"--mode latest"`: follow the head of the chain and gossip latest blocks
- `"--mode test:/path/to/test_data.json"`: gossip content keys & values found in test file.
- `"--mode backfill:b100"`: start backfill at block #100
- `"--mode backfill:e100"`: start backfill at epoch #100
- `"--mode backfill:r10-12"`: backfill a block range from #10 to #12 (inclusive)
- `"--mode single:b100"`: gossip a single block #100
- `"--mode single:e100"`: gossip a single epoch #100
- `"--mode fourfours`: will randomly select era1 files from `era1.ethportal.net` and gossip them
- `"--mode fourfours:random_epoch"`: will randomly select a single era1 file from `era1.ethportal.net` and then gossip it
- `"--mode fourfours:random_epoch:100"`: will randomly select a single era1 file from `era1.ethportal.net` that represents an epoch number greater than the floor provided and then gossip it
- `"--mode fourfours:e600`: will select era1 file 600 from `era1.ethportal.net` and gossip it
- `"--mode fourfours:r100-200`: will gossip a block range from an era1 file, range must be from the same epoch
- `"--mode fourfours:hunter:10:50`: sample size = 10, threshold = 50
- will randomly select era1 files from `era1.ethportal.net` and gossip them after performing rfc lookups given the sample size. if the threshold is **not** met, the era1 file will be gossiped.
- before gossiping a individual piece of content, the bridge will perform a lookup to see if the content is already in the portal network. If it is, the content will not be gossiped.
- `"--mode fourfours:single_hunter:10:50`: sample size = 10, threshold = 50
- same as the above hunter mode, but it will only gossip a single era1 file before exiting

#### E2HS Bridge
#### History Network E2HS Bridge

- `"--mode e2hs --e2hs-range 100-200"`: gossip a block range from #100 to #200 (inclusive) using `E2HS` files as the data source
- `"--mode e2hs --e2hs-range 1000-10000 --e2hs-randomize"`: randomize the order in which epochs from block range are gossiped
Expand All @@ -57,7 +36,6 @@ cargo run -p portal-bridge -- --executable-path ./target/debug/trin --epoch-accu

#### State Subnetwork

- `"--mode single:b100"`: backfill, always beginning from block #0 until the specified block (#100)
- `"--mode single:r50-100"`: backfill, gossips state diffs for blocks in #50-#100 range (inclusive)
- `"--mode snapshot:1000000"`: gossips a state snapshot at the respective block, in this example the state snapshot at block 1,000,000 will be gossiped. This mode is only used for the State Network.

Expand All @@ -68,7 +46,7 @@ You can specify the `--portal-subnetworks` flag for which network to run the bri
- `"--portal-subnetworks history"`: Default value. Run the bridge for the history network.
- `"--portal-subnetworks beacon"`: Run the bridge for the beacon network.
- `"--portal-subnetworks history,beacon"`: Run the bridge for the history & beacon network.
` "--portal-subnetworks state"`: Run the bridge for the state network.
- `"--portal-subnetworks state"`: Run the bridge for the state network.
- Currently, the `"state"` network can only be run by itself!

### Test File example
Expand Down
Loading