Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
204 commits
Select commit Hold shift + click to select a range
c457ed3
add doppelganger endpoint
realbigsean Feb 17, 2021
2e2a699
add doppelganger detection methods and fix endpoint
realbigsean Feb 19, 2021
80f83ec
add validator client logic and API test
realbigsean Feb 26, 2021
61b4472
add simulator test and add log
realbigsean Feb 27, 2021
f27ee39
add log
realbigsean Feb 27, 2021
478f245
fix typo and comparator bug
realbigsean Feb 27, 2021
502052a
move log
realbigsean Feb 27, 2021
e3958e2
delete log
realbigsean Feb 27, 2021
050f439
fix doppelganger detection loop
realbigsean Feb 27, 2021
5cb18b0
add breaks
realbigsean Feb 27, 2021
51e4286
Use the database to persist the pubkey cache
michaelsproul Mar 1, 2021
dd24c8f
pr updates
realbigsean Mar 1, 2021
dfcec9c
pr updates
realbigsean Mar 1, 2021
752a3cf
Add first pass at using pre-state for block prod
paulhauner Mar 2, 2021
ed61c44
Add warnings for late block broadcasts
paulhauner Mar 2, 2021
27efac4
Move warnings for late blocks
paulhauner Mar 2, 2021
22ab61b
Add comments
paulhauner Mar 2, 2021
c35a6c4
Use crit for late blocks
paulhauner Mar 2, 2021
d274b32
Tidy docs, add sanity check
paulhauner Mar 2, 2021
53b4457
Add more metrics for duties
paulhauner Mar 3, 2021
54940bd
Refactor proposer duties endpoint
paulhauner Mar 3, 2021
23ca805
Fix bug in state advance timer
paulhauner Mar 3, 2021
fe57bfb
Remove old beacon proposer cache
paulhauner Mar 3, 2021
906d72b
First refactor of attester duties
paulhauner Mar 3, 2021
b3954a5
Merge branch 'pr/2234' into faster-duties
paulhauner Mar 3, 2021
57723c8
Add pubkey bytes struct
paulhauner Mar 4, 2021
484cf45
Almost complete duties refactor
paulhauner Mar 4, 2021
8984b90
Add almost-compiling refactor
paulhauner Mar 4, 2021
cedea75
Remove old duties service code
paulhauner Mar 4, 2021
cd7edcd
Merge branch 'unstable' into faster-duties
paulhauner Mar 4, 2021
c32e5ca
Fix compile errors
paulhauner Mar 4, 2021
1653482
Remove old validator_duty struct
paulhauner Mar 4, 2021
c552d87
Fix attestation, indices bugs
paulhauner Mar 4, 2021
0449301
Fix clippy lints, add metrics
paulhauner Mar 4, 2021
60e1a7d
Specify integer types
paulhauner Mar 4, 2021
db023dc
Revert "Specify integer types"
paulhauner Mar 4, 2021
16ae38c
Only subscribe for later slots
paulhauner Mar 4, 2021
c1c8326
Specify integers as slots
paulhauner Mar 4, 2021
733257e
Use saturating math
paulhauner Mar 4, 2021
d456fc0
Subscribe even later
paulhauner Mar 4, 2021
b1ca126
make doppelganger detection default behavior, move it to a service, t…
realbigsean Mar 4, 2021
8b7aa54
Merge branch 'faster-duties' of https://github.com/sigp/lighthouse in…
realbigsean Mar 4, 2021
9e9307f
Fix slashing test compile errors
paulhauner Mar 4, 2021
bc1ffd9
clean up
realbigsean Mar 4, 2021
80e5dba
clippy fixes
realbigsean Mar 5, 2021
34a91e7
Fix slashing db compile error
paulhauner Mar 5, 2021
66c7038
Add comments, fancy block retry logic
paulhauner Mar 5, 2021
94f7df5
Fix test compile error
paulhauner Mar 5, 2021
e8e2f14
Tidy
paulhauner Mar 5, 2021
a78078b
Break proposer duties into own file, refactor
paulhauner Mar 5, 2021
9a11075
update error handling and filtering for signing keys
realbigsean Mar 5, 2021
90ade56
Merge branch 'faster-duties' of https://github.com/sigp/lighthouse in…
realbigsean Mar 5, 2021
66b035b
return which validators have been seen from the `seen_validators` end…
realbigsean Mar 5, 2021
1d4db15
Avoid bouncing pubkey lock
paulhauner Mar 6, 2021
0c1a25c
Improve test coverage, fix bugs
paulhauner Mar 6, 2021
da4b6ff
Test for proposer cache changes
paulhauner Mar 6, 2021
78c246f
Test proposer duties from future epoch
paulhauner Mar 6, 2021
a7e50d8
Add first pass of attn duties refactor
paulhauner Mar 6, 2021
421f829
Fix failing test
paulhauner Mar 7, 2021
c902885
Cache next-epoch duties during state advance
paulhauner Mar 7, 2021
d4a7b66
Update comment
paulhauner Mar 7, 2021
7c977e0
Add more debugging for shuffling cache
paulhauner Mar 7, 2021
d851b7d
Reduce logging for cache
paulhauner Mar 7, 2021
1fbb98d
Add more VC metrics
paulhauner Mar 7, 2021
29e024a
Avoid state read for committee cache
paulhauner Mar 7, 2021
256e00d
More VC metrics
paulhauner Mar 7, 2021
30f7772
Fix clippy lint
paulhauner Mar 7, 2021
8383eec
Merge branch 'faster-duties' of https://github.com/sigp/lighthouse in…
realbigsean Mar 8, 2021
c6ca63f
tests
realbigsean Mar 11, 2021
a6d9ca2
Merge branch 'unstable' of https://github.com/sigp/lighthouse into do…
realbigsean Mar 17, 2021
cd8683c
merge fixes
realbigsean Mar 17, 2021
15d2bbd
fix sim
realbigsean Mar 17, 2021
35920b0
debugging
realbigsean Mar 17, 2021
6fd2de2
fix slot clock read
realbigsean Mar 17, 2021
dabd838
Merge branch 'unstable' of https://github.com/sigp/lighthouse into do…
realbigsean Mar 19, 2021
bd469af
fix no eth1 sim
realbigsean Mar 19, 2021
6435114
cargo fmt
realbigsean Mar 19, 2021
a2522b1
fix logic to keep validators from proposing/attesting
realbigsean Mar 21, 2021
2665fde
update log
realbigsean Mar 21, 2021
4e78a85
update log
realbigsean Mar 21, 2021
f612b0f
critical bug
realbigsean Mar 21, 2021
b7aae27
move indices to validator store
realbigsean Mar 21, 2021
72a33a8
move indices to validator store
realbigsean Mar 22, 2021
99b4a7e
fix log
realbigsean Mar 22, 2021
211bf30
fix log
realbigsean Mar 22, 2021
c7b0626
shutdown sender testing
realbigsean Mar 23, 2021
74f314a
attempt to fix simulator
realbigsean Mar 23, 2021
efc15e3
attempt to fix simulator
realbigsean Mar 23, 2021
c494e61
revert simulator changes
realbigsean Mar 29, 2021
8961838
Merge branch 'unstable' of https://github.com/sigp/lighthouse into do…
realbigsean Mar 29, 2021
45e4025
Merge branch 'unstable' of https://github.com/sigp/lighthouse into do…
realbigsean Mar 30, 2021
ff554a4
doppelganger detection test script
realbigsean Apr 2, 2021
2f01019
fix timeout
realbigsean Apr 4, 2021
58077db
debug
realbigsean Apr 5, 2021
5aa3420
move to script test dir in test suite
realbigsean Apr 5, 2021
8c9027b
test failure
realbigsean Apr 5, 2021
1d7d7d2
test failure
realbigsean Apr 5, 2021
abaccef
test success
realbigsean Apr 5, 2021
1614386
Accept validator ids rather than pubkeys in the seen_validators endpo…
realbigsean Apr 5, 2021
58a780d
increase doppelganger detection timeout time
realbigsean Apr 5, 2021
63c4651
typo
realbigsean Apr 5, 2021
d136c08
Merge branch 'unstable' of https://github.com/sigp/lighthouse into do…
realbigsean Apr 23, 2021
72c0c51
General PR updates
realbigsean Apr 23, 2021
0dfa14e
Updates to match Paul's API spec proposal
realbigsean Apr 23, 2021
b700e85
fix clippy errors
realbigsean Apr 23, 2021
646cdfa
Merge branch 'unstable' of https://github.com/sigp/lighthouse into do…
realbigsean Apr 29, 2021
d16e76b
address most of the new PR feedback
realbigsean Apr 29, 2021
2856fdd
Track completed epochs by decrementing `num_remaining_detection_epochs`
realbigsean May 3, 2021
91eedd1
Merge branch 'unstable' of https://github.com/sigp/lighthouse into do…
realbigsean May 5, 2021
cf4a21d
cargo lock update
realbigsean May 5, 2021
1668933
Change break -> continue
paulhauner May 5, 2021
60a7376
Change logs for global consistency
paulhauner May 5, 2021
02e61c3
Add incomplete progress
paulhauner May 5, 2021
e39feee
sensitive url fix
realbigsean May 5, 2021
3bd276c
Restrict signing based on doppelganger
paulhauner May 7, 2021
f9473d2
Add comments, fix violator detection
paulhauner May 7, 2021
604a551
Merge branch 'unstable' into sean-dopple
paulhauner Jun 9, 2021
93e3b32
Add comment
paulhauner Jun 10, 2021
9b77a31
Further tidying
paulhauner Jun 10, 2021
814e96b
Introduce VotingPubkey enum
paulhauner Jun 11, 2021
5471973
Rename function
paulhauner Jun 11, 2021
18e0284
Fix test compile error
paulhauner Jun 11, 2021
90317e9
Tidy
paulhauner Jun 11, 2021
138ddba
Rename VotingPubkey -> DoppelgangerStatus
paulhauner Jun 11, 2021
6d156a9
Add doppelganger protection comment
paulhauner Jun 11, 2021
a4216c3
Rename DoppelgangerStatus fns
paulhauner Jun 11, 2021
c0c859c
Tidy comments
paulhauner Jun 11, 2021
568670d
Skip validators with inconsistencies, tidy
paulhauner Jun 15, 2021
b146c27
Don't exit if BN returns nothing for liveness
paulhauner Jun 15, 2021
91e182d
Appease clippy
paulhauner Jun 15, 2021
589477e
Refactor to smaller functions
paulhauner Jun 15, 2021
b5fe24e
Make `detect_doppelgangers` more generic
paulhauner Jun 15, 2021
ff22c03
Use generic shutdown signal
paulhauner Jun 16, 2021
eb5e9c9
Add first tests
paulhauner Jun 16, 2021
521eb70
Add more testing
paulhauner Jun 16, 2021
a78cc52
More testing
paulhauner Jun 16, 2021
d73b9dd
Add success scenario test
paulhauner Jun 16, 2021
002c9e6
Add skip forward test
paulhauner Jun 16, 2021
00813e1
Add time skip backwards test
paulhauner Jun 16, 2021
7c9ec9f
Add staggered entry test
paulhauner Jun 16, 2021
8304496
Remove slot clock from doppelganger
paulhauner Jun 17, 2021
10bec29
Update comment
paulhauner Jun 17, 2021
a3d9854
Allow selection proof signing
paulhauner Jun 17, 2021
fc451bd
Add comment
paulhauner Jun 17, 2021
acdc615
Merge branch 'unstable' of https://github.com/sigp/lighthouse into do…
realbigsean Jun 17, 2021
d690ef4
Fixes related to merge with `unstable`
realbigsean Jun 17, 2021
4c2817e
add newline
realbigsean Jun 17, 2021
704723a
test shutdown reason success exit code
realbigsean Jun 17, 2021
cb991b4
Test failure
realbigsean Jun 17, 2021
47d4b37
rust 1.53.0 updates
realbigsean Jun 17, 2021
28f668c
add recursion limit to `simulator` crate
realbigsean Jun 17, 2021
bd7f9d9
cargo fmt
realbigsean Jun 17, 2021
e9bb44f
Merge branch 'rust-1.53.0-lints' of https://github.com/realbigsean/li…
realbigsean Jun 17, 2021
2d2e9f1
Test success
realbigsean Jun 17, 2021
284ee60
Merge branch 'doppleganger-detection' of https://github.com/realbigse…
realbigsean Jun 17, 2021
1bac50f
fix duplicate `Cargo.toml` entry
realbigsean Jun 17, 2021
d48f84e
- move `DetectionState` mutation to method.
realbigsean Jun 29, 2021
70a4e5a
fix comments, set `DEFAULT_REMAINING_DETECTION_EPOCHS` to 1
realbigsean Jun 29, 2021
0d9c187
Disable doppelganger detection by default
realbigsean Jun 29, 2021
7e7dcb6
Add doppelganger status endpoint
realbigsean Jul 2, 2021
59f272a
Add doppelganger protection enabled method
realbigsean Jul 2, 2021
c3e8585
Add docs, fix tests and some comments
realbigsean Jul 2, 2021
7bd8240
Merge branch 'unstable' of https://github.com/sigp/lighthouse into do…
realbigsean Jul 2, 2021
88b7de7
Merge branch 'doppleganger-detection' of https://github.com/realbigse…
realbigsean Jul 2, 2021
72b5f88
Merge branch 'unstable' of https://github.com/sigp/lighthouse into pa…
realbigsean Jul 7, 2021
a35bf31
- And an `Arc` around the `ValidatorStore`
realbigsean Jul 7, 2021
ce55743
- Add local testnet test for successful doppelganger protection period
realbigsean Jul 8, 2021
f4aee3c
remove unncessary `mut`
realbigsean Jul 8, 2021
08e67f4
update doppelganger test in ci
realbigsean Jul 8, 2021
135c130
Merge branch 'unstable' of https://github.com/sigp/lighthouse into do…
realbigsean Jul 12, 2021
9324b6f
update cargo lock
realbigsean Jul 12, 2021
a9283a3
Merge branch 'doppleganger-detection' of https://github.com/realbigse…
realbigsean Jul 12, 2021
56b921d
Add a timeout for the liveness request
realbigsean Jul 12, 2021
e786eb7
fix test compilation after merge
realbigsean Jul 12, 2021
b213f1b
Use Option instead of enabled bool
paulhauner Jul 13, 2021
2bf2860
fix typo and add fork slot to test `.env` files
realbigsean Jul 13, 2021
6e2484c
fix tests
realbigsean Jul 13, 2021
97d6151
Merge pull request #16 from realbigsean/paul-sean-dopple
realbigsean Jul 13, 2021
95cb6b5
improve doppelganger success test
realbigsean Jul 26, 2021
0186494
update seconds per slot on success
realbigsean Jul 26, 2021
0657a7f
fix local testnet
realbigsean Jul 26, 2021
a0d9acc
Merge branch 'unstable' of https://github.com/sigp/lighthouse into do…
realbigsean Jul 26, 2021
35c9472
self review updates
realbigsean Jul 27, 2021
26a6c0d
Revert "Add doppelganger status endpoint"
realbigsean Jul 27, 2021
6ceecc5
Small fixes
realbigsean Jul 27, 2021
8412d59
make seconds per eth2 slot default to 3 in scripts
realbigsean Jul 27, 2021
064e4ae
remove duplicate vars.env file
realbigsean Jul 27, 2021
a400352
add cli test for doppelganger flag
realbigsean Jul 27, 2021
8c21e5d
verbose commands
realbigsean Jul 27, 2021
e180def
add lines to debug
realbigsean Jul 27, 2021
52ab06c
Merge branch 'unstable' of https://github.com/sigp/lighthouse into do…
realbigsean Jul 28, 2021
f2d026e
update `is_current_epoch_attester` to `is_current_epoch_target_attest…
realbigsean Jul 28, 2021
7d5a955
Merge branch 'unstable' of https://github.com/sigp/lighthouse into do…
realbigsean Jul 28, 2021
1b196d7
increase bootnode startup wait time
realbigsean Jul 28, 2021
de0d6dc
increase seconds per slot
realbigsean Jul 28, 2021
baa893e
increase seconds per slot
realbigsean Jul 28, 2021
2452794
increase seconds per slot
realbigsean Jul 28, 2021
1396ae9
update to use previous epoch inclusion
realbigsean Jul 28, 2021
7f3c607
Merge branch 'unstable' of https://github.com/sigp/lighthouse into do…
realbigsean Jul 30, 2021
7794be0
Update validator_client/src/doppelganger_service.rs
realbigsean Jul 30, 2021
2634f96
Update validator_client/src/doppelganger_service.rs
realbigsean Jul 30, 2021
f1c1dd3
Update validator_client/src/doppelganger_service.rs
realbigsean Jul 30, 2021
08b9692
Merge branch 'doppleganger-detection' of https://github.com/realbigse…
realbigsean Jul 30, 2021
0a1eac4
PR updates plus a few extra lints
realbigsean Jul 30, 2021
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
22 changes: 22 additions & 0 deletions .github/workflows/test-suite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,28 @@ jobs:
run: sudo npm install -g ganache-cli
- name: Run the syncing simulator
run: cargo run --release --bin simulator syncing-sim
doppelganger-protection-test:
name: doppelganger-protection-test
runs-on: ubuntu-latest
needs: cargo-fmt
steps:
- uses: actions/checkout@v1
- name: Get latest version of stable Rust
run: rustup update stable
- name: Install ganache-cli
run: sudo npm install -g ganache-cli
- name: Install lighthouse and lcli
run: |
make
make install-lcli
- name: Run the doppelganger protection success test script
run: |
cd scripts/tests
./doppelganger_protection.sh success
- name: Run the doppelganger protection failure test script
run: |
cd scripts/tests
./doppelganger_protection.sh failure
check-benchmarks:
name: check-benchmarks
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

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

22 changes: 22 additions & 0 deletions beacon_node/beacon_chain/src/beacon_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3443,6 +3443,28 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
let mut file = std::fs::File::create(file_name).unwrap();
self.dump_as_dot(&mut file);
}

/// Checks if attestations have been seen from the given `validator_index` at the
/// given `epoch`.
pub fn validator_seen_at_epoch(&self, validator_index: usize, epoch: Epoch) -> bool {
// It's necessary to assign these checks to intermediate variables to avoid a deadlock.
//
// See: https://github.com/sigp/lighthouse/pull/2230#discussion_r620013993
let attested = self
.observed_attesters
.read()
.index_seen_at_epoch(validator_index, epoch);
let aggregated = self
.observed_aggregators
.read()
.index_seen_at_epoch(validator_index, epoch);
let produced_block = self
.observed_block_producers
.read()
.index_seen_at_epoch(validator_index as u64, epoch);

attested || aggregated || produced_block
}
}

impl<T: BeaconChainTypes> Drop for BeaconChain<T> {
Expand Down
10 changes: 10 additions & 0 deletions beacon_node/beacon_chain/src/observed_attesters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,16 @@ impl<T: Item, E: EthSpec> AutoPruningEpochContainer<T, E> {
pub(crate) fn get_lowest_permissible(&self) -> Epoch {
self.lowest_permissible_epoch
}

/// Returns `true` if the given `index` has been stored in `self` at `epoch`.
///
/// This is useful for doppelganger detection.
pub fn index_seen_at_epoch(&self, index: usize, epoch: Epoch) -> bool {
self.items
.get(&epoch)
.map(|item| item.contains(index))
.unwrap_or(false)
}
}

/// A container that stores some number of `V` items.
Expand Down
11 changes: 10 additions & 1 deletion beacon_node/beacon_chain/src/observed_block_producers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use std::collections::{HashMap, HashSet};
use std::marker::PhantomData;
use types::{BeaconBlockRef, EthSpec, Slot, Unsigned};
use types::{BeaconBlockRef, Epoch, EthSpec, Slot, Unsigned};

#[derive(Debug, PartialEq)]
pub enum Error {
Expand Down Expand Up @@ -114,6 +114,15 @@ impl<E: EthSpec> ObservedBlockProducers<E> {
self.finalized_slot = finalized_slot;
self.items.retain(|slot, _set| *slot > finalized_slot);
}

/// Returns `true` if the given `validator_index` has been stored in `self` at `epoch`.
///
/// This is useful for doppelganger detection.
pub fn index_seen_at_epoch(&self, validator_index: u64, epoch: Epoch) -> bool {
self.items.iter().any(|(slot, producers)| {
slot.epoch(E::slots_per_epoch()) == epoch && producers.contains(&validator_index)
})
}
}

#[cfg(test)]
Expand Down
44 changes: 44 additions & 0 deletions beacon_node/http_api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1907,6 +1907,49 @@ pub fn serve<T: BeaconChainTypes>(
},
);

// POST lighthouse/liveness
let post_lighthouse_liveness = warp::path("lighthouse")
.and(warp::path("liveness"))
.and(warp::path::end())
.and(warp::body::json())
.and(chain_filter.clone())
.and_then(
|request_data: api_types::LivenessRequestData, chain: Arc<BeaconChain<T>>| {
blocking_json_task(move || {
// Ensure the request is for either the current, previous or next epoch.
let current_epoch = chain
.epoch()
.map_err(warp_utils::reject::beacon_chain_error)?;
let prev_epoch = current_epoch.saturating_sub(Epoch::new(1));
let next_epoch = current_epoch.saturating_add(Epoch::new(1));

if request_data.epoch < prev_epoch || request_data.epoch > next_epoch {
return Err(warp_utils::reject::custom_bad_request(format!(
"request epoch {} is more than one epoch from the current epoch {}",
request_data.epoch, current_epoch
)));
}

let liveness: Vec<api_types::LivenessResponseData> = request_data
.indices
.iter()
.cloned()
.map(|index| {
let is_live =
chain.validator_seen_at_epoch(index as usize, request_data.epoch);
api_types::LivenessResponseData {
index: index as u64,
epoch: request_data.epoch,
is_live,
}
})
.collect();

Ok(api_types::GenericResponse::from(liveness))
})
},
);

// GET lighthouse/health
let get_lighthouse_health = warp::path("lighthouse")
.and(warp::path("health"))
Expand Down Expand Up @@ -2249,6 +2292,7 @@ pub fn serve<T: BeaconChainTypes>(
.or(post_beacon_pool_voluntary_exits.boxed())
.or(post_validator_duties_attester.boxed())
.or(post_validator_aggregate_and_proofs.boxed())
.or(post_lighthouse_liveness.boxed())
.or(post_validator_beacon_committee_subscriptions.boxed()),
))
.recover(warp_utils::reject::handle_rejection)
Expand Down
67 changes: 67 additions & 0 deletions beacon_node/http_api/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2149,6 +2149,71 @@ impl ApiTester {
self
}

pub async fn test_post_lighthouse_liveness(self) -> Self {
let epoch = self.chain.epoch().unwrap();
let head_state = self.chain.head_beacon_state().unwrap();
let indices = (0..head_state.validators().len())
.map(|i| i as u64)
.collect::<Vec<_>>();

// Construct the expected response
let expected: Vec<LivenessResponseData> = head_state
.validators()
.iter()
.enumerate()
.map(|(index, _)| LivenessResponseData {
index: index as u64,
is_live: false,
epoch,
})
.collect();

let result = self
.client
.post_lighthouse_liveness(indices.as_slice(), epoch)
.await
.unwrap()
.data;

assert_eq!(result, expected);

// Attest to the current slot
self.client
.post_beacon_pool_attestations(self.attestations.as_slice())
.await
.unwrap();

let result = self
.client
.post_lighthouse_liveness(indices.as_slice(), epoch)
.await
.unwrap()
.data;

let committees = head_state
.get_beacon_committees_at_slot(self.chain.slot().unwrap())
.unwrap();
let attesting_validators: Vec<usize> = committees
.into_iter()
.map(|committee| committee.committee.iter().cloned())
.flatten()
.collect();
// All attesters should now be considered live
let expected = expected
.into_iter()
.map(|mut a| {
if attesting_validators.contains(&(a.index as usize)) {
a.is_live = true;
}
a
})
.collect::<Vec<_>>();

assert_eq!(result, expected);

self
}

pub async fn test_get_events(self) -> Self {
// Subscribe to all events
let topics = vec![
Expand Down Expand Up @@ -2635,5 +2700,7 @@ async fn lighthouse_endpoints() {
.test_get_lighthouse_beacon_states_ssz()
.await
.test_get_lighthouse_staking()
.await
.test_post_lighthouse_liveness()
.await;
}
25 changes: 25 additions & 0 deletions book/src/api-lighthouse.md
Original file line number Diff line number Diff line change
Expand Up @@ -329,3 +329,28 @@ curl -X GET "http://localhost:5052/lighthouse/beacon/states/0/ssz" | jq
```

*Example omitted for brevity, the body simply contains SSZ bytes.*

### `/lighthouse/liveness`

POST request that checks if any of the given validators have attested in the given epoch. Returns a list
of objects, each including the validator index, epoch, and `is_live` status of a requested validator.

This endpoint is used in doppelganger detection, and will only provide accurate information for the
current, previous, or next epoch.


```bash
curl -X POST "http://localhost:5052/lighthouse/liveness" -d '{"indices":["0","1"],"epoch":"1"}' -H "content-type: application/json" | jq
```

```json
{
"data": [
{
"index": "0",
"epoch": "1",
"is_live": true
}
]
}
```
2 changes: 1 addition & 1 deletion book/src/api-vc-endpoints.md
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ Typical Responses | 200
"checksum": {
"function": "sha256",
"params": {

},
"message": "abadc1285fd38b24a98ac586bda5b17a8f93fc1ff0778803dc32049578981236"
},
Expand Down
26 changes: 26 additions & 0 deletions common/eth2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ impl fmt::Display for Error {
pub struct Timeouts {
pub attestation: Duration,
pub attester_duties: Duration,
pub liveness: Duration,
pub proposal: Duration,
pub proposer_duties: Duration,
}
Expand All @@ -92,6 +93,7 @@ impl Timeouts {
Timeouts {
attestation: timeout,
attester_duties: timeout,
liveness: timeout,
proposal: timeout,
proposer_duties: timeout,
}
Expand Down Expand Up @@ -1103,6 +1105,30 @@ impl BeaconNodeHttpClient {
.await
}

/// `POST lighthouse/liveness`
pub async fn post_lighthouse_liveness(
&self,
ids: &[u64],
epoch: Epoch,
) -> Result<GenericResponse<Vec<LivenessResponseData>>, Error> {
let mut path = self.server.full.clone();

path.path_segments_mut()
.map_err(|()| Error::InvalidUrl(self.server.clone()))?
.push("lighthouse")
.push("liveness");

self.post_with_timeout_and_response(
path,
&LivenessRequestData {
indices: ids.to_vec(),
epoch,
},
self.timeouts.liveness,
)
.await
}

/// `POST validator/duties/attester/{epoch}`
pub async fn post_validator_duties_attester(
&self,
Expand Down
15 changes: 15 additions & 0 deletions common/eth2/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -847,6 +847,21 @@ impl FromStr for Accept {
}
}

#[derive(Debug, Serialize, Deserialize)]
pub struct LivenessRequestData {
pub epoch: Epoch,
#[serde(with = "serde_utils::quoted_u64_vec")]
pub indices: Vec<u64>,
}

#[derive(PartialEq, Debug, Serialize, Deserialize)]
pub struct LivenessResponseData {
#[serde(with = "serde_utils::quoted_u64")]
pub index: u64,
pub epoch: Epoch,
pub is_live: bool,
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
7 changes: 7 additions & 0 deletions lcli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,13 @@ fn main() {
non-default.",
),
)
.arg(
Arg::with_name("seconds-per-slot")
.long("seconds-per-slot")
.value_name("SECONDS")
.takes_value(true)
.help("Eth2 slot time"),
)
.arg(
Arg::with_name("seconds-per-eth1-block")
.long("seconds-per-eth1-block")
Expand Down
1 change: 1 addition & 0 deletions lcli/src/new_testnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ pub fn run<T: EthSpec>(testnet_dir_path: PathBuf, matches: &ArgMatches) -> Resul
maybe_update!("genesis-delay", genesis_delay);
maybe_update!("eth1-id", deposit_chain_id);
maybe_update!("eth1-id", deposit_network_id);
maybe_update!("seconds-per-slot", seconds_per_slot);
maybe_update!("seconds-per-eth1-block", seconds_per_eth1_block);

if let Some(v) = parse_ssz_optional(matches, "genesis-fork-version")? {
Expand Down
13 changes: 13 additions & 0 deletions lighthouse/tests/validator_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,3 +378,16 @@ pub fn malloc_tuning_flag() {
// effects of it.
.run();
}
#[test]
fn doppelganger_protection_flag() {
CommandLineTest::new()
.flag("enable-doppelganger-protection", None)
.run()
.with_config(|config| assert!(config.enable_doppelganger_protection));
}
#[test]
fn no_doppelganger_protection_flag() {
CommandLineTest::new()
.run()
.with_config(|config| assert!(!config.enable_doppelganger_protection));
}
Loading