Skip to content

Commit 6483aea

Browse files
committed
refactor: remove unsupported bridge modes
1 parent 22b31a9 commit 6483aea

File tree

26 files changed

+88
-1972
lines changed

26 files changed

+88
-1972
lines changed

Diff for: .circleci/config.yml

-3
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,6 @@ jobs:
9797
steps:
9898
- checkout
9999
- setup_remote_docker
100-
- run:
101-
name: Clone portal-accumulators
102-
command: git clone https://github.com/ethereum/portal-accumulators
103100
- run:
104101
name: Build Docker bridge image
105102
no_output_timeout: 30m

Diff for: .dockerignore

-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,3 @@
1010

1111
# include for vergen constants
1212
!/.git
13-
14-
# include portal-accumulators, which is used in the portal-bridge Dockerfile
15-
!/portal-accumulators

Diff for: Cargo.lock

-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ rust-version = "1.85.0"
3737
version = "0.2.1"
3838

3939
[workspace.dependencies]
40-
alloy = { version = "0.12", default-features = false, features = ["std"] }
40+
alloy = { version = "0.12", default-features = false, features = ["std", "serde"] }
4141
alloy-rlp = { version = "0.3.8", default-features = false, features = ["derive"] }
4242
anyhow = "1.0.68"
4343
async-trait = "0.1.68"

Diff for: bin/e2hs-writer/src/cli.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
use std::path::PathBuf;
22

33
use clap::Parser;
4-
use portal_bridge::{cli::DEFAULT_EPOCH_ACC_PATH, DEFAULT_BASE_EL_ENDPOINT};
4+
use portal_bridge::DEFAULT_BASE_EL_ENDPOINT;
55
use url::Url;
66

7+
pub const DEFAULT_EPOCH_ACC_PATH: &str = "./portal-accumulators";
8+
79
#[derive(Parser, Debug, Clone)]
810
#[command(name = "E2HS Writer", about = "Generate E2HS files")]
911
pub struct WriterConfig {

Diff for: bin/e2hs-writer/src/reader.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use ethportal_api::types::{
2121
},
2222
};
2323
use futures::Stream;
24-
use portal_bridge::{api::execution::ExecutionApi, bridge::utils::lookup_epoch_acc};
24+
use portal_bridge::api::execution::ExecutionApi;
2525
use ssz_types::{typenum, FixedVector, VariableList};
2626
use tokio::try_join;
2727
use tree_hash::TreeHash;
@@ -35,7 +35,10 @@ use url::Url;
3535

3636
use crate::{
3737
provider::EraProvider,
38-
utils::{pre_capella_execution_payload_to_header, pre_deneb_execution_payload_to_header},
38+
utils::{
39+
lookup_epoch_acc, pre_capella_execution_payload_to_header,
40+
pre_deneb_execution_payload_to_header,
41+
},
3942
};
4043

4144
pub struct AllBlockData {

Diff for: bin/e2hs-writer/src/utils.rs

+35-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::{fs, path::Path};
2+
13
use alloy::{
24
consensus::{
35
proofs::{calculate_transaction_root, calculate_withdrawals_root},
@@ -6,11 +8,17 @@ use alloy::{
68
eips::eip4895::Withdrawal,
79
primitives::{Bloom, B64, U256},
810
};
9-
use anyhow::ensure;
10-
use ethportal_api::types::consensus::execution_payload::{
11-
ExecutionPayloadBellatrix, ExecutionPayloadCapella,
11+
use anyhow::{anyhow, ensure};
12+
use ethportal_api::{
13+
types::{
14+
consensus::execution_payload::{ExecutionPayloadBellatrix, ExecutionPayloadCapella},
15+
execution::accumulator::EpochAccumulator,
16+
},
17+
utils::bytes::hex_encode,
1218
};
19+
use ssz::Decode;
1320
use trin_execution::era::beacon::EMPTY_UNCLE_ROOT_HASH;
21+
use trin_validation::accumulator::PreMergeAccumulator;
1422

1523
pub fn pre_capella_execution_payload_to_header(
1624
payload: ExecutionPayloadBellatrix,
@@ -85,3 +93,27 @@ pub fn pre_deneb_execution_payload_to_header(
8593
);
8694
Ok(header)
8795
}
96+
97+
/// Lookup the epoch accumulator & epoch hash for the given epoch index.
98+
pub async fn lookup_epoch_acc(
99+
epoch_index: u64,
100+
pre_merge_acc: &PreMergeAccumulator,
101+
epoch_acc_path: &Path,
102+
) -> anyhow::Result<EpochAccumulator> {
103+
let epoch_hash = pre_merge_acc.historical_epochs[epoch_index as usize];
104+
let epoch_hash_pretty = hex_encode(epoch_hash);
105+
let epoch_hash_pretty = epoch_hash_pretty.trim_start_matches("0x");
106+
let epoch_acc_path = format!(
107+
"{}/bridge_content/0x03{epoch_hash_pretty}.portalcontent",
108+
epoch_acc_path.display(),
109+
);
110+
let epoch_acc = match fs::read(&epoch_acc_path) {
111+
Ok(val) => EpochAccumulator::from_ssz_bytes(&val).map_err(|err| anyhow!("{err:?}"))?,
112+
Err(_) => {
113+
return Err(anyhow!(
114+
"Unable to find local epoch acc at path: {epoch_acc_path:?}"
115+
))
116+
}
117+
};
118+
Ok(epoch_acc)
119+
}

Diff for: bin/portal-bridge/Cargo.toml

-2
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,12 @@ version.workspace = true
1414
[dependencies]
1515
alloy.workspace = true
1616
anyhow.workspace = true
17-
async-trait.workspace = true
1817
chrono.workspace = true
1918
clap.workspace = true
2019
delay_map.workspace = true
2120
discv5.workspace = true
2221
e2store.workspace = true
2322
eth_trie.workspace = true
24-
ethereum_ssz.workspace = true
2523
ethportal-api.workspace = true
2624
futures.workspace = true
2725
humanize-duration.workspace = true

Diff for: bin/portal-bridge/README.md

+3-25
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ Process to feed the portal network by gossiping data retrieved from a trusted pr
44

55
ex.
66
```sh
7-
git clone https://github.com/ethereum/portal-accumulators.git
8-
cargo run -p portal-bridge -- --executable-path ./target/debug/trin --epoch-accumulator-path ./portal-accumulators
7+
cargo run -p portal-bridge -- --executable-path ./target/debug/trin
98
```
109

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

2625
### Bridge modes
2726

28-
#### History Subnetwork
29-
30-
- `"--mode latest"`: follow the head of the chain and gossip latest blocks
31-
- `"--mode test:/path/to/test_data.json"`: gossip content keys & values found in test file.
32-
- `"--mode backfill:b100"`: start backfill at block #100
33-
- `"--mode backfill:e100"`: start backfill at epoch #100
34-
- `"--mode backfill:r10-12"`: backfill a block range from #10 to #12 (inclusive)
35-
- `"--mode single:b100"`: gossip a single block #100
36-
- `"--mode single:e100"`: gossip a single epoch #100
37-
- `"--mode fourfours`: will randomly select era1 files from `era1.ethportal.net` and gossip them
38-
- `"--mode fourfours:random_epoch"`: will randomly select a single era1 file from `era1.ethportal.net` and then gossip it
39-
- `"--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
40-
- `"--mode fourfours:e600`: will select era1 file 600 from `era1.ethportal.net` and gossip it
41-
- `"--mode fourfours:r100-200`: will gossip a block range from an era1 file, range must be from the same epoch
42-
- `"--mode fourfours:hunter:10:50`: sample size = 10, threshold = 50
43-
- 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.
44-
- 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.
45-
- `"--mode fourfours:single_hunter:10:50`: sample size = 10, threshold = 50
46-
- same as the above hunter mode, but it will only gossip a single era1 file before exiting
47-
48-
#### E2HS Bridge
27+
#### History Network E2HS Bridge
4928

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

5837
#### State Subnetwork
5938

60-
- `"--mode single:b100"`: backfill, always beginning from block #0 until the specified block (#100)
6139
- `"--mode single:r50-100"`: backfill, gossips state diffs for blocks in #50-#100 range (inclusive)
6240
- `"--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.
6341

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

7452
### Test File example

0 commit comments

Comments
 (0)