Compare commits

...

169 Commits

Author SHA1 Message Date
rauljordan
7dd1ce957f beacon 2021-09-29 14:57:06 -04:00
rauljordan
673a845918 testing 2021-09-29 14:50:43 -04:00
rauljordan
15a024f171 e2e 2021-09-29 14:49:07 -04:00
rauljordan
618e7d8f89 confs 2021-09-29 14:45:55 -04:00
Raul Jordan
26de0f1358 rem sim 2021-09-28 22:31:49 -04:00
Raul Jordan
5f38167cd9 sync 2021-09-28 22:30:46 -04:00
rauljordan
a0193ca90c sync 2021-09-28 17:12:51 -04:00
Raul Jordan
0fc5b27195 Merge branch 'develop' into feature/slasher 2021-09-28 14:18:06 -05:00
rauljordan
2a9a978fc6 fix conflicts 2021-09-28 15:09:42 -04:00
Raul Jordan
9a78ce007a fix conflicts 2021-09-13 15:36:35 -04:00
rauljordan
16febfe6d9 merge develop 2021-08-24 16:05:07 -05:00
rauljordan
db57c45ec9 merge develop 2021-08-24 16:03:47 -05:00
Raul Jordan
0d99862e42 sync develop 2021-08-17 11:21:11 -06:00
Raul Jordan
a4f35f4b09 sync develop 2021-08-10 14:42:24 -06:00
Raul Jordan
ebb1fe80f9 Merge branch 'develop' into feature/slasher 2021-08-05 14:52:05 -05:00
Raul Jordan
ab071834fb fix some tests 2021-08-05 13:49:32 -06:00
Raul Jordan
e27fb164a3 Merge branch 'feature/slasher' of github.com:prysmaticlabs/prysm into feature/slasher 2021-08-05 11:48:22 -06:00
Raul Jordan
7b807a6c01 fix build 2021-08-05 11:47:51 -06:00
Raul Jordan
33e6908c71 Merge branch 'develop' into feature/slasher 2021-08-05 12:46:29 -05:00
Raul Jordan
bac54f53ab gaz 2021-08-05 11:40:18 -06:00
Raul Jordan
960d39c859 fix deepsource 2021-08-05 10:59:23 -06:00
Raul Jordan
fc951b4416 regen protos 2021-08-05 10:30:53 -06:00
Raul Jordan
4d2a01e6df fix conflicts 2021-08-05 09:57:29 -06:00
Raul Jordan
3121501e80 remove old slasher 2021-08-05 08:56:02 -06:00
Raul Jordan
65656045f9 resolve more conflicts 2021-08-04 22:45:52 -06:00
Raul Jordan
59b38ed293 merge develop 2021-08-04 21:33:42 -06:00
Raul Jordan
963f61f1fb End-to-End Test Suite For Synced Slasher Node (#9169)
* begin slasher-sync-e2e

* all changes required for slasher sync e2e

* gaz

* commentary

* false test deposits

* skip e2e until functionality is checked in
2021-08-02 08:44:02 -05:00
Raul Jordan
1e8720057e Benchmarks for Detect Slashable Attestations (#9175)
* atts benchmark

* require errcheck

* handle errvalues
2021-07-13 13:27:34 -05:00
Raul Jordan
2fa80c35dc Merge branch 'develop' into feature/slasher 2021-07-13 09:47:02 -04:00
Raul Jordan
96852134ab add sync checker in node startup for slasher 2021-07-08 13:55:59 -05:00
Raul Jordan
2606935c42 Merge branch 'develop' into feature/slasher 2021-07-08 13:31:49 -05:00
Raul Jordan
c6ca50e766 pass missing tests 2021-07-08 13:30:53 -05:00
Raul Jordan
3433002bae Merge branch 'develop' into feature/slasher 2021-07-08 10:52:18 -05:00
Raul Jordan
ce9df503b3 Reduce Duplication of Attestations in SlasherDB (#9130)
* remove fastsum of attesting indices

* gazelle
2021-07-07 16:29:54 +00:00
Raul Jordan
b93d925047 do not run slasher if syncing the chain 2021-07-07 11:29:07 -05:00
Raul Jordan
1df73a698b gaz 2021-07-07 09:27:17 -05:00
Raul Jordan
ca2461491c merge develop 2021-07-07 09:10:01 -05:00
Raul Jordan
83fb66b9d5 allow compile 2021-06-30 15:33:37 -05:00
rauljordan
ab3ffb5d38 info verbosity for pruning 2021-06-30 12:08:11 -05:00
Raul Jordan
28fbbbdf7f display pruned items 2021-06-29 21:23:58 -05:00
Raul Jordan
eb612d81b1 Parallelized Double Vote Detection in Slasher With Disk-Space Efficient Schema (#9086)
* use errgroup to optimize double vote detection and use a more disk-space-efficient schema

* errgroup find
2021-06-23 21:41:39 +00:00
Raul Jordan
601fbbfb3a merge in develop 2021-06-23 15:21:05 -06:00
Raul Jordan
f4d3eec431 amend import not found 2021-06-18 09:34:00 -05:00
Raul Jordan
b3ffac459a add slasher handler 2021-06-18 09:26:09 -05:00
Raul Jordan
2e1b8190eb merge develop 2021-06-18 09:25:19 -05:00
Raul Jordan
bf14b28ca9 Merge branch 'develop' into feature/slasher 2021-06-17 20:24:51 -05:00
Raul Jordan
b4b6f25386 improve tests to use head slot 2021-06-17 14:50:07 -05:00
rauljordan
f5f95d8f99 sync with develop 2021-06-17 13:39:49 -05:00
Raul Jordan
d93369294c Merge branch 'develop' into feature/slasher 2021-06-11 14:03:14 -05:00
Raul Jordan
ad0332ba41 build 2021-06-10 16:58:15 -05:00
Raul Jordan
18d00724b2 remove ethereumapis 2021-06-10 16:46:08 -05:00
Raul Jordan
a21b98bfd3 merge develop 2021-06-10 16:29:23 -05:00
Raul Jordan
35b853c958 Merge branch 'develop' into feature/slasher 2021-05-21 14:35:34 -05:00
Raul Jordan
401f73d341 Merge branch 'develop' into feature/slasher 2021-05-20 11:11:08 -05:00
Raul Jordan
403389a0d8 Use Pruning Sliding Window for Slasher (#8911)
* proper sliding window pruning for slasher

* test passing for attestation pruning

* proposals get pruned

* amend pruning tests

* added log

* Update beacon-chain/db/slasherkv/pruning.go

Co-authored-by: Radosław Kapka <rkapka@wp.pl>

* Update beacon-chain/db/slasherkv/pruning.go

Co-authored-by: Radosław Kapka <rkapka@wp.pl>

* Update beacon-chain/db/slasherkv/pruning.go

Co-authored-by: Radosław Kapka <rkapka@wp.pl>

* Update beacon-chain/db/slasherkv/pruning.go

Co-authored-by: Radosław Kapka <rkapka@wp.pl>

* Update beacon-chain/db/slasherkv/pruning.go

Co-authored-by: Radosław Kapka <rkapka@wp.pl>

* Update beacon-chain/db/slasherkv/pruning.go

Co-authored-by: Radosław Kapka <rkapka@wp.pl>

* remaining comments

* Update beacon-chain/db/slasherkv/slasher.go

Co-authored-by: Preston Van Loon <preston@prysmaticlabs.com>

* preston comments

Co-authored-by: Radosław Kapka <rkapka@wp.pl>
Co-authored-by: Preston Van Loon <preston@prysmaticlabs.com>
2021-05-20 11:10:51 -05:00
Raul Jordan
8c5d577636 merge develop 2021-05-18 18:59:34 -05:00
Raul Jordan
f4d54506a0 Merge branch 'develop' into feature/slasher 2021-05-07 16:18:53 -05:00
Raul Jordan
44f6ec48b8 Merge branch 'develop' into feature/slasher 2021-05-05 12:14:35 -05:00
Raul Jordan
2958c84872 Ensure Validator Has No Breaking Changes in New Slasher (#8862)
* add new flag to prevent breaking changes

* pass tests

* gaz

* rename to old slasher

* rem deprecation

* passing tests
2021-05-05 12:14:16 -05:00
rauljordan
e9d670f16f build file confs 2021-05-04 11:42:25 -05:00
rauljordan
7194d025ba fix up conflicts 2021-05-04 11:38:03 -05:00
Raul Jordan
0776639772 Merge branch 'develop' into feature/slasher 2021-05-03 20:32:35 -05:00
Raul Jordan
68d43a9e90 fix confs 2021-05-03 15:44:47 -05:00
Raul Jordan
e18cca94c9 Merge branch 'develop' into feature/slasher 2021-04-28 09:41:32 -05:00
Raul Jordan
08df279330 Merge branch 'develop' into feature/slasher 2021-04-27 19:03:04 -05:00
rauljordan
c80fc63c9f fix sim 2021-04-23 14:40:25 -05:00
rauljordan
1df189339a Merge branch 'develop' into feature/slasher 2021-04-23 12:06:25 -05:00
rauljordan
c0246bd82e add back ensure embedded 2021-04-23 10:35:29 -05:00
rauljordan
12ed20f341 fix e2e conflicts 2021-04-23 09:56:31 -05:00
terence tsao
9824e17c83 Merge branch 'develop' into feature/slasher 2021-04-22 09:46:37 -07:00
Raul Jordan
f4e247808a Merge branch 'develop' into feature/slasher 2021-04-21 08:46:30 -05:00
Raul Jordan
8dcfa40807 Merge branch 'develop' into feature/slasher 2021-04-20 10:00:42 -05:00
Raul Jordan
89ee961354 Merge branch 'develop' into feature/slasher 2021-04-19 08:39:43 -05:00
rauljordan
ad30274a2d gaz 2021-04-16 15:29:27 -05:00
rauljordan
91ce227966 passthrough 2021-04-16 14:53:14 -05:00
rauljordan
dd4154aed9 fmt 2021-04-16 14:48:09 -05:00
rauljordan
6f97ff2219 merge develop 2021-04-16 14:45:28 -05:00
Raul Jordan
ac44476977 Batch Pruning for Optimized Slasher (#8764)
* cursor-based pruning

* pruning logic with commentary

* full algo

* proper conditional

* better log

* edit log

* improvements to alg

* it worked

* begin same pruning process for attestations, correctness first, then deduplication later

* slasher prune atts test

* better prune

* pass pruning tests

* gaz

* fix slasher build

* ineff assing

* remove irrelevant test

* highest attestations passing

* Victor's suggestion

* Update beacon-chain/db/slasherkv/pruning.go

Co-authored-by: Victor Farazdagi <simple.square@gmail.com>

* Update beacon-chain/db/slasherkv/pruning.go

Co-authored-by: Victor Farazdagi <simple.square@gmail.com>

* added test main to file

Co-authored-by: Victor Farazdagi <simple.square@gmail.com>
2021-04-16 14:40:01 -05:00
Raul Jordan
6cecb79988 Optimized Slasher Should Use its Own DB File (#8749)
* unique database for slasher content

* use beacon db for simulator for stategen

* build

* prom

* gaz

* change viz

* remove duplicate metrics collection

* revert

* revert
2021-04-13 21:59:04 -05:00
Raul Jordan
67ac7a7455 Merge branch 'develop' into feature/slasher 2021-04-13 20:38:59 -05:00
Raul Jordan
4e6981374e Merge branch 'develop' into feature/slasher 2021-04-13 12:59:43 -05:00
Raul Jordan
21b33d3883 Merge branch 'develop' into feature/slasher 2021-04-10 11:37:19 -05:00
Raul Jordan
ca5527e331 Merge branch 'develop' into feature/slasher 2021-04-09 15:45:39 -05:00
Raul Jordan
cb0450eb23 Save Attestations in Slasher's History During Remote Protection (#8726)
* mark attestations

* pass tests

* comment
2021-04-09 15:45:27 -05:00
Raul Jordan
9a75bb9d5a Merge branch 'develop' into feature/slasher 2021-04-08 09:32:41 -05:00
rauljordan
71f9b8be87 fix build 2021-04-08 09:28:45 -05:00
rauljordan
03b1bc12a6 fix confs 2021-04-08 09:14:04 -05:00
rauljordan
3a7ce95dc2 Merge branch 'develop' of github.com:prysmaticlabs/prysm into develop 2021-04-08 09:11:22 -05:00
Raul Jordan
dfb0209f01 Use Optimized Slasher in E2E Code (#8718)
* new slasher in e2e

* propose block investigation

* slasher e2e tests all passes
2021-04-08 08:59:04 -05:00
Raul Jordan
5a22c5c2b0 Optimized Slasher Better DB Schema (#8720)
* optimize

* optimized db storage

* comments

* ivan comments
2021-04-08 07:43:59 -05:00
Raul Jordan
7734ae1006 Fix Optimized Remote Slashing Protection (#8719)
* fix remote slashing response

* gaz
2021-04-07 14:17:13 -05:00
Raul Jordan
71ac917ba8 Space Efficiency in Slasher DB Schema, Add More Metrics (#8701)
* add new encoding functions to save on space

* slasher more space efficient

* opt and fix slasher tests

* merge

* compile

* unused funcs

* broken tests

* use consistent, history length

* tests passing

* use types.epoch

* microopt
2021-04-06 08:46:19 -05:00
Raul Jordan
8836445dff conflict 2021-04-05 15:00:13 -05:00
rauljordan
661bf55961 deep source issues 2021-04-05 11:46:03 -05:00
Raul Jordan
48d1b8766e Merge branch 'feature/slasher' of github.com:prysmaticlabs/prysm into feature/slasher 2021-03-30 16:04:44 -05:00
Raul Jordan
1127851899 more realistic params for slasher e2e 2021-03-30 16:04:37 -05:00
Raul Jordan
bcbfa26fbd Merge branch 'develop' into feature/slasher 2021-03-30 15:58:18 -05:00
Raul Jordan
dd5b19f3de improve e2e resilience 2021-03-30 15:57:08 -05:00
Raul Jordan
c3084a2cfe merge e2e changes 2021-03-30 13:27:55 -05:00
Raul Jordan
c0e49a4217 Utilize Optimized Slasher for Remote Slashing Protection in Validator Client (#8674)
* begin removal of slasher client

* update mockgen

* removal of old slasher remote protector

* pass tests

* rename feature flag

* all tests pass

* deprecate the slasher grpc provider flags

* fix broken build

* time since
2021-03-29 16:35:25 -05:00
Raul Jordan
425816a2b4 compile 2021-03-26 18:59:18 -05:00
Raul Jordan
dd8e4edb41 better logging 2021-03-26 18:57:57 -05:00
Raul Jordan
7e3dae42c0 Optimize Slasher DB Operations (#8677)
Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
2021-03-26 23:32:42 +00:00
Raul Jordan
d629297b80 fix feed items 2021-03-26 16:38:26 -05:00
Raul Jordan
abbc66e617 change simulator params 2021-03-26 09:49:54 -05:00
rauljordan
905f5c3c88 Merge branch 'feature/slasher' of github.com:prysmaticlabs/prysm into feature/slasher 2021-03-25 22:44:17 -05:00
rauljordan
980fab5439 detect slashable attestations tests moved to a better file 2021-03-25 22:44:09 -05:00
Ivan Martinez
a2b80eceb6 Add HighestAttestations function (#8654)
* Add HighestAttestations function

* Fix

* Fix

* Add benchmarks

* Change n

* Fix

* Remove N assignment

* Fix timer

* Change to encIndices

* skip deprecated slasher test

Co-authored-by: Raul Jordan <raul@prysmaticlabs.com>
Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
2021-03-25 21:40:35 +00:00
Ivan Martinez
3c4b858c99 Mark old slasher client as deprecated (#8666)
* Mark all old slasher as deprecated

* Update slasher/node/node.go

* README

Co-authored-by: Raul Jordan <raul@prysmaticlabs.com>
2021-03-25 15:16:28 +00:00
Raul Jordan
082bb19c6d sim fix 2021-03-25 08:47:32 -05:00
Raul Jordan
10f6f06bb8 seconds per slot increase 2021-03-25 08:46:25 -05:00
Raul Jordan
dd31cfb929 increase seconds per slot 2021-03-25 08:46:01 -05:00
rauljordan
23cbd504ba reduce 2021-03-24 19:18:09 -05:00
Raul Jordan
be711a820e tidy 2021-03-24 17:59:04 -05:00
Raul Jordan
376f661f8a Merge branch 'develop' into feature/slasher 2021-03-24 17:58:49 -05:00
Raul Jordan
5cb12099e9 Process Found Slashings and Send to Operations Pool in Optimized Slasher (#8634)
* add in pool inserter

* integrate process slashings functions

* should return err

* add head state fetcher

* utilize head fetcher in process slashings

* builds but some tests fail

* simulator needs to be aware of genesis state

* rem testonly

* attestation tests passing

* attempt more test fixes

* all slasher tests passing, missing sim

* fix test

* add priv keys to simulator

* add pool

* valid sigs generated

* add valid signatures to attestations in simulator

* begin fixing simulator tests

* pass simulator tests

* gaz

* viz

* passing e2e

* slasher tests passing

* no lock

* pass

* build

* mock

* compile issues

* deep source
2021-03-24 22:51:11 +00:00
Raul Jordan
a430a4b8ae go sum 2021-03-24 15:33:55 -05:00
Raul Jordan
4526483392 Merge branch 'develop' into feature/slasher 2021-03-24 14:58:34 -05:00
Raul Jordan
0efb3ec54e resolve broken build 2021-03-24 14:35:25 -05:00
Raul Jordan
254cd6def0 merge develop 2021-03-24 14:26:45 -05:00
Raul Jordan
4943d635cd Test Actual Simulator Code in E2E, Remove Simulator Binary for Optimized Slasher (#8649)
* migrate simulator to test package

* sim test

* create slashing test

* res
2021-03-23 13:55:10 -05:00
Ivan Martinez
5184d63801 Add IsSlashableBlock and IsSlashableAttestation endpoints to beacon node (#8616)
* expose rpc slasher

* Imports

* Progress on endpoint

* Fix for commit, work on server integration

* refactor attestations

* genesis

* Undo gRPC changes

* Revert "Undo gRPC changes"

This reverts commit 4c0ac4c6c4.

* Cleanup

* Finish testing

* Fixes

* Plug slasher server into rpc

* more cleanups and correct placement of slasher service in node.go

* tests pass

* rpc annotate

* Add tests and mock

* Fix errors and duplicate

* Fix

* Add slasher check to service

* Fix

Co-authored-by: Raul Jordan <raul@prysmaticlabs.com>
2021-03-22 22:14:59 -05:00
Ivan Martinez
8d5c44ff77 Reorganize Slasher Detection (#8625)
* expose rpc slasher

* Imports

* Progress on endpoint

* Fix for commit, work on server integration

* refactor attestations

* Undo gRPC changes

* Fix conflict

* Remove IsSlashableBlock

* Fixes

* Clean up

* Fixes

* resolved genesis time test

* Fix logging

* Fixes

* Fixes

* Fix kafka

* Fix

* Fixes:wq
Gaz

* Fix test

* Fix suggestion

Co-authored-by: Raul Jordan <raul@prysmaticlabs.com>
2021-03-19 16:33:12 +00:00
Raul Jordan
8901cbc574 Verify Signatures of Detected Offenses in Optimized Slasher (#8626)
* smaller iface

* add validate funcs

* verify more slashings

* add verify sig and stategen

* more tests

* verification functions

* gaz

* broken test

* builds

* rename to att target state

* added sig verify test

* gaz
2021-03-19 08:40:58 -05:00
Raul Jordan
8fff0b6ca7 Integrate Optimized Slasher Into Beacon Node Runtime, Part 1 (#8602)
* initial runtime integration

* slasher integration

* revert

* revert

* use a genesis time fetcher

* define genesis time fetcher

* gaz

* use feature flag

* pass tests

* add in chain start notifier

* add enable slasher config value

* ensure slasher starts with the proper genesis time

* more input fix

* integrate slasher into blockchain and sync pipelines

* elim comment

* define right feeds

* fix some test builds

* fix sim

* goroutine for start func

* slasher genesis time

* pass in feeds to blockchain service

* change logs

* Update beacon-chain/sync/validate_beacon_attestation.go

Co-authored-by: terence tsao <terence@prysmaticlabs.com>

* add tests for logging

* add in tests for logging

* do not send block in blockchain service

* gaz

* fix build

Co-authored-by: terence tsao <terence@prysmaticlabs.com>
2021-03-17 15:22:28 -05:00
Ivan Martinez
e7e62f5234 Add Slasher Simulator to E2E (#8604)
* Add simulator to e2e

* Fix E2E for simulator

* Add comment

* Fixes

* Add simulator logs to error logging
2021-03-16 02:43:19 +00:00
Raul Jordan
8f7c4cea4e Defer Attestations for Future Processing in Optimized Slasher (#8594)
* begin defer atts

* add in deferred processing logic

* all helper function tests passing

* remove irrelevant test

* fix typo

* remove unused metric

* Fix for terences comments

* Fixes

Co-authored-by: Ivan Martinez <ivanthegreatdev@gmail.com>
2021-03-15 20:03:45 -05:00
Raul Jordan
d7af14128e Add Slasher Simulator for Profiling, Benchmarking, and Testing (#8495)
* begin slasher simulator

* use slot ticker instead

* Begin on attestation generator

* Add block and att generator

* Fix tests

* Fix att generation

* Add test for generated indices

* Fix visibility

* Cleanup

* Add aggregation precent

* revert config

* revert

* pass tests

* imports

* commentary

* cmd

* Add logfile flag

* add better err handling

* add more detailed logging

* added more logging events

* gazelle

* merge and pass slasher tests

* move to cmd

* Add Ability for Slasher Simulator to Verify Slashings Are Detected (#8580)

* Collect slashings WIP

* Fix prob

* imports

* implement simulation check routine

* simulator overriding config working

* include the slashable att

* not catching slashings yet

* more fixes

* Change to e2e config and clean up logging

* Patch some more gaps

* imports

* detected prop slashings

* fully functional

* caught

* gaz

* sim

* Remove TODO

* Fix tests

* Fix gaz

* deepsource

* Deepsource

Co-authored-by: Raul Jordan <raul@prysmaticlabs.com>

* Fix build

* Fixes

Co-authored-by: Ivan Martinez <ivanthegreatdev@gmail.com>
2021-03-12 20:48:48 +00:00
Ivan Martinez
87bf2296a2 Add pruning functionality to slasher (#8591)
* Add pruning to slasher by historySize

* Add pruning to execution

* Plug in functionality

* Fix

* Add pruning to separate routine

* Fixes

* Fix tests
2021-03-12 04:43:50 +00:00
Raul Jordan
963d42567c Define Slasher gRPC Server and Endpoints (#8595)
* begin defining protos

* definition

* ethereumapis dep

* added in slasher pbs

* define implementations

* add in slasher

* edit vis
2021-03-11 13:36:41 -06:00
Ivan Martinez
daa575b87c Add slashing feeds to slasher (#8568)
* Add feeds for slashings

* Add slashing feedss

* Fix

* fix imports

* Update beacon-chain/slasher/detect_blocks.go

Co-authored-by: Raul Jordan <raul@prysmaticlabs.com>
2021-03-08 10:52:59 -06:00
Raul Jordan
346629b205 Snappy Compress Slasher Chunks (#8561)
* work towards compression

* slasher chunks compressed

* fix params test

* go deep source

* chunk keys test

Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
2021-03-05 18:52:36 +00:00
Ivan Martinez
f5f97c3d1f Prepare slasher to construct full slashing proof (#8551)
* Prepare slasher to construct full slashing proof

* Fix comments

* Fix tests

* Fix tests

* Fix tests
2021-03-05 10:13:59 -06:00
Raul Jordan
5259a4b698 Metrics for Optimized Slasher (#8560)
* add metrics

* track metrics

* gaz

* add in all slasher metrics

* remove bad metric
2021-03-05 02:23:26 +00:00
Raul Jordan
746315815e go mod tidy 2021-03-04 16:48:46 -06:00
Raul Jordan
5678fbe591 Merge branch 'develop' into feature/slasher 2021-03-04 16:41:20 -06:00
Raul Jordan
a82fc98453 Better Error Messages in Optimized Slasher (#8553)
* better annotated errors

* handle last err

Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
2021-03-04 20:32:21 +00:00
Raul Jordan
30fec47d57 Merge branch 'develop' into feature/slasher 2021-03-04 11:34:42 -06:00
Raul Jordan
fd33c70a5c Fallback to DB When Retrieving Missing Chunk in Optimized Slasher (#8548)
* begin more comprehensive tests across epoch boundaries

* add in lock

* integrate changes from Ivan's PR

* minimal reproduction

* fix chunk index issue

* passing tests

* gaz

* naming
2021-03-03 15:44:40 -06:00
Ivan Martinez
ec678939a8 Store full IndexedAttestation and SignedBeaconBlockHeader for slasher (#8536)
* Change DB and slasher to handle full attestation/block header objects

* Undo proto

* Add comments

* work on tests

* Fix tests

* Fixes

* Testing fixes

* Fix tests

* Fix again

* add helper

* Fix build

* Fixes

* Fixes

* Fixes

* Comment fixes

* More comments

* fix
2021-03-03 11:30:48 -06:00
Raul Jordan
9553b82ed3 Merge branch 'develop' into feature/slasher 2021-03-01 20:18:48 -06:00
Raul Jordan
0bb61cf3fe Merge branch 'develop' into feature/slasher 2021-02-22 11:37:47 -06:00
Raul Jordan
f7cc07c750 Merge branch 'develop' into feature/slasher 2021-02-22 11:24:20 -06:00
Raul Jordan
c56d09dff3 Attester Double Vote Detection for Optimized Slasher (#8480)
* update routine added

* test build fix

* begin adding integration test

* proper logging of slashing events

* commentary and examples for next start epoch interface methods

* include comprehensive comments for new iface methods

* better comments

* integration tests for surrounding, surrounded, and not slashable

* test for logging helper

* tests for the next start epoch methods

* typo

* add in methods and tests

* add start epoch tests

* tests for new methods added

* tests pass

* passing test

* imports spacing

* add all required logic to check for double vote

* check double vote logic

* amend db func

* check on disk

* more efficient db method

* tests passing

* check respect to each other

* add tests for double vote detection

* gaz

* tests passed

* fix passthrough build

* double gaz

* add in spans

* faster concat

* gaz
2021-02-22 11:13:55 -06:00
Raul Jordan
8cdbcd9700 Double Block Slashing Detection for Optimized Slasher (#8470)
* add double block detect

* db tests'

* kafka deepsource

* imports

* comment

* address all Radek's comments

* add comment

* comment to check double proposals on disk

* fix kafka passthrough.go build

* pass tests

* comment

* build

* deep source

* imports

* imports
2021-02-22 09:50:19 -06:00
Radosław Kapka
19ae9b5590 Remove mutated fields from slasher args (#8487) 2021-02-22 08:45:20 -06:00
Raul Jordan
2913947c24 Detect Slashable Surround Votes in Optimized Slasher (#8446)
* update routine added

* test build fix

* begin adding integration test

* proper logging of slashing events

* commentary and examples for next start epoch interface methods

* include comprehensive comments for new iface methods

* better comments

* integration tests for surrounding, surrounded, and not slashable

* test for logging helper

* tests for the next start epoch methods

* typo

* add in methods and tests

* add start epoch tests

* tests for new methods added

* tests pass

* passing test

* imports spacing

* tests passing

* db test passing

* radek comments

* deep source

* added more test cases

* further simplify

* passthrough

* comment on struct

* commentary on skipping validator chunk index

* map capacity
2021-02-19 09:53:29 -06:00
Raul Jordan
c342d35bbf Begin Receiving and Processing Blocks for Optimized Slasher (#8450)
* add in receive blocks logic

* use different locks

* add unit test for block receiver functions

* fix types

* build fix

* terence feedback

* fix broken build
2021-02-17 13:15:25 -06:00
Raul Jordan
b285722f5c fix e2e build 2021-02-17 11:44:58 -06:00
Raul Jordan
16c6ea9489 fix build issues when merging with develop 2021-02-17 11:35:08 -06:00
Raul Jordan
72bfb94e53 merge develop 2021-02-17 10:56:55 -06:00
Raul Jordan
976297725a deps fix 2021-02-15 23:38:34 -06:00
Raul Jordan
9b6f93184d Merge branch 'develop' into feature/slasher 2021-02-15 23:35:40 -06:00
Raul Jordan
a6fde55646 Methods For StartEpoch and Slashing Helper Types for Optimized Slasher (#8442)
* add in methods and tests

* add start epoch tests

* tests for new methods added

* tests pass

* Update beacon-chain/slasher/chunks.go

Co-authored-by: Preston Van Loon <preston@prysmaticlabs.com>

* Update beacon-chain/slasher/chunks.go

Co-authored-by: Preston Van Loon <preston@prysmaticlabs.com>

* right order of operations

* fix order

* order

* tests

* comment

* even more simplification

* comments

Co-authored-by: Preston Van Loon <preston@prysmaticlabs.com>
2021-02-12 16:18:04 -06:00
Raul Jordan
a48de9ab69 Detection Algorithm for Optimized Slasher (#8423)
* detect

* more separation of concerns

* leverage the chunk kind type to create the same functionality easily

* builds

* begin writing tests

* add even more tests to our logic

* using fewer input args via opts struct

* all comments done for new functions

* fix build

* improvement to helpers

* determine chunk indices to load, then fetch all in batch

* batch load chunks

* add test for determine chunks for update

* all tests pass

* gaz

* fix kafka passthrough build

* deep source
2021-02-10 13:19:53 -06:00
rauljordan
429c94534e simplify and cleanup 2021-02-09 21:47:58 -06:00
rauljordan
12defb914d passthrough fix 2021-02-05 14:14:36 -06:00
Raul Jordan
ce9cf8cf1f Merge branch 'develop' into feature/slasher 2021-02-05 14:11:58 -06:00
Raul Jordan
5596f8b0d4 Detection Further Helpers and Types for Attester Slashing Detection (#8400)
* compact rename

* rename

* imports

* add import

* tests
2021-02-05 11:11:25 -06:00
Raul Jordan
2864d5f070 Add Helpers Required for Attestation Slashing Detection, Begin Detection Framework (#8386)
* include detection functions

* begin detection helpers such as batching and grouping indexed attestations

* add more tests to the detection process

* tests done for detection helpers

* add proper todo format

* test

* terence comments

* better queue safety with lock

* with fields for logrus
2021-02-03 14:33:05 -06:00
Raul Jordan
38d681341c Merge branch 'develop' into feature/slasher 2021-02-02 16:54:42 -06:00
Radosław Kapka
90f2ef801a Remove redundant bool return value from CheckSlashable (#8375) 2021-02-01 16:12:00 +00:00
Raul Jordan
d9bbbe5a4e Implement MaxSpanChunksSlice for Optimized Slasher (#8358)
* add in max spans logic

* tests for check slashable max

* max span chunks complete

* named params

* better comment
2021-01-29 11:05:05 -06:00
Raul Jordan
24dde8fb82 merge 2021-01-28 19:42:53 -06:00
Raul Jordan
b6b5bb0c51 Merge branch 'develop' into feature/slasher 2021-01-28 19:42:23 -06:00
Raul Jordan
971a15f907 Defining and Implementing the Chunker Interface for MinSpans (#8350)
* chunker methods and comments

* more chunker tests

* add more chunk tests

* tests passing, now missing update test

* better comment

* gaz

* better annotations

* test for updating a single chunk

* multiple chunks test

* fix test to use deepequal

* chunks tests now properly passing

* deep source fixes

* better annotation for epoch staggering

* victor comments
2021-01-28 14:21:13 -06:00
Raul Jordan
3e2c6a9522 Add Database Schema and Methods for Optimized Slasher (#8342)
* begin adding db schema

* define required schema

* add eth2 types

* use custom types helpers

* begin tests for schema

* update deps

* edit workspace

* gaz

* passthrough

* gaz

* terence feedback
2021-01-27 15:38:03 -06:00
Raul Jordan
939a36df58 Begin Slasher Service Definition and Configuration (#8335)
* begin defining the service itself

* tests for receive atts

* begin defining necessary config helpers

* thorough comments

* more tests

* 100% coverage and docs

* gazelle

* terence feedback

* types

* rename

* fix build
2021-01-26 13:00:49 -06:00
Raul Jordan
de89d816ad begin slasher package 2021-01-25 16:03:44 -06:00
24 changed files with 161 additions and 501 deletions

View File

@@ -6,6 +6,7 @@
mock_path="shared/mock"
mocks=(
"$mock_path/beacon_service_mock.go BeaconChainClient,BeaconChain_StreamChainHeadClient,BeaconChain_StreamAttestationsClient,BeaconChain_StreamBlocksClient,BeaconChain_StreamValidatorsInfoClient,BeaconChain_StreamIndexedAttestationsClient"
"$mock_path/slasher_service_mock.go SlasherClient"
"$mock_path/beacon_chain_service_mock.go BeaconChain_StreamChainHeadServer,BeaconChain_StreamAttestationsServer,BeaconChain_StreamBlocksServer,BeaconChain_StreamValidatorsInfoServer,BeaconChain_StreamIndexedAttestationsServer"
"$mock_path/beacon_validator_server_mock.go BeaconNodeValidatorServer,BeaconNodeValidator_WaitForActivationServer,BeaconNodeValidator_WaitForChainStartServer,BeaconNodeValidator_StreamDutiesServer"
"$mock_path/beacon_validator_client_mock.go BeaconNodeValidatorClient,BeaconNodeValidator_WaitForChainStartClient,BeaconNodeValidator_WaitForActivationClient,BeaconNodeValidator_StreamDutiesClient"
@@ -19,7 +20,6 @@ for ((i = 0; i < ${#mocks[@]}; i++)); do
interfaces=${mocks[i]#* };
echo "generating $file for interfaces: $interfaces";
GO11MODULE=on mockgen -package=mock -destination="$file" github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1 "$interfaces"
GO11MODULE=on mockgen -package=mock -destination="$file" github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1 "$interfaces"
done
goimports -w "$mock_path/."

View File

@@ -64,7 +64,7 @@
"external/.*": "Third party code",
"rules_go_work-.*": "Third party code",
"config/params/config.go": "This config struct needs to be organized for now",
"shared/featureconfig/config.go": "This config struct needs to be organized for now",
"config/features/config.go": "This config struct needs to be organized for now",
"proto/.*": "Excluding protobuf objects for now"
}
},

View File

@@ -26,6 +26,7 @@ go_library(
"//async/event:go_default_library",
"//beacon-chain/core:go_default_library",
"//beacon-chain/core/altair:go_default_library",
"//beacon-chain/core/blocks:go_default_library",
"//beacon-chain/core/signing:go_default_library",
"//cache/lru:go_default_library",
"//config/features:go_default_library",
@@ -53,7 +54,6 @@ go_library(
"//validator/keymanager:go_default_library",
"//validator/keymanager/imported:go_default_library",
"//validator/keymanager/remote:go_default_library",
"//validator/slashing-protection/iface:go_default_library",
"@com_github_dgraph_io_ristretto//:go_default_library",
"@com_github_ferranbt_fastssz//:go_default_library",
"@com_github_grpc_ecosystem_go_grpc_middleware//:go_default_library",

View File

@@ -81,8 +81,12 @@ func (v *validator) slashableAttestationCheck(
return errors.Wrap(err, "could not save attestation history for validator public key")
}
if features.Get().RemoteSlasherProtection && v.protector != nil {
if !v.protector.CheckAttestationSafety(ctx, indexedAtt) {
if features.Get().RemoteSlasherProtection {
slashing, err := v.slashingProtectionClient.IsSlashableAttestation(ctx, indexedAtt)
if err != nil {
return errors.Wrap(err, "could not check if attestation is slashable")
}
if slashing != nil && len(slashing.AttesterSlashings) > 0 {
if v.emitAccountMetrics {
ValidatorAttestFailVecSlasher.WithLabelValues(fmtKey).Inc()
}

View File

@@ -10,7 +10,6 @@ import (
"github.com/prysmaticlabs/prysm/encoding/bytesutil"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/testing/require"
mockSlasher "github.com/prysmaticlabs/prysm/validator/testing"
)
func Test_slashableAttestationCheck(t *testing.T) {
@@ -19,7 +18,7 @@ func Test_slashableAttestationCheck(t *testing.T) {
}
reset := features.InitWithReset(config)
defer reset()
validator, _, validatorKey, finish := setup(t)
validator, m, validatorKey, finish := setup(t)
defer finish()
pubKey := [48]byte{}
copy(pubKey[:], validatorKey.PublicKey().Marshal())
@@ -39,11 +38,23 @@ func Test_slashableAttestationCheck(t *testing.T) {
},
},
}
mockProtector := &mockSlasher.MockProtector{AllowAttestation: false}
validator.protector = mockProtector
m.slasherClient.EXPECT().IsSlashableAttestation(
gomock.Any(), // ctx
gomock.Any(),
).Return(&ethpb.AttesterSlashingResponse{AttesterSlashings: []*ethpb.AttesterSlashing{{
Attestation_1: &ethpb.IndexedAttestation{},
Attestation_2: &ethpb.IndexedAttestation{},
}}}, nil /*err*/)
err := validator.slashableAttestationCheck(context.Background(), att, pubKey, [32]byte{1})
require.ErrorContains(t, failedPostAttSignExternalErr, err)
mockProtector.AllowAttestation = true
m.slasherClient.EXPECT().IsSlashableAttestation(
gomock.Any(), // ctx
gomock.Any(),
).Return(&ethpb.AttesterSlashingResponse{}, nil /*err*/)
err = validator.slashableAttestationCheck(context.Background(), att, pubKey, [32]byte{1})
require.NoError(t, err, "Expected allowed attestation not to throw error")
}
@@ -75,18 +86,23 @@ func Test_slashableAttestationCheck_UpdatesLowestSignedEpochs(t *testing.T) {
},
},
}
mockProtector := &mockSlasher.MockProtector{AllowAttestation: false}
validator.protector = mockProtector
m.slasherClient.EXPECT().IsSlashableAttestation(
gomock.Any(), // ctx
gomock.Any(),
).Return(&ethpb.AttesterSlashingResponse{}, nil /*err*/)
m.validatorClient.EXPECT().DomainData(
gomock.Any(), // ctx
&ethpb.DomainRequest{Epoch: 10, Domain: []byte{1, 0, 0, 0}},
).Return(&ethpb.DomainResponse{SignatureDomain: make([]byte, 32)}, nil /*err*/)
_, sr, err := validator.getDomainAndSigningRoot(ctx, att.Data)
require.NoError(t, err)
mockProtector.AllowAttestation = true
err = validator.slashableAttestationCheck(context.Background(), att, pubKey, sr)
require.NoError(t, err)
differentSigningRoot := [32]byte{2}
err = validator.slashableAttestationCheck(context.Background(), att, pubKey, differentSigningRoot)
require.ErrorContains(t, "could not sign attestation", err)
@@ -102,12 +118,12 @@ func Test_slashableAttestationCheck_UpdatesLowestSignedEpochs(t *testing.T) {
func Test_slashableAttestationCheck_OK(t *testing.T) {
config := &features.Flags{
RemoteSlasherProtection: false,
RemoteSlasherProtection: true,
}
reset := features.InitWithReset(config)
defer reset()
ctx := context.Background()
validator, _, _, finish := setup(t)
validator, mocks, _, finish := setup(t)
defer finish()
att := &ethpb.IndexedAttestation{
AttestingIndices: []uint64{1, 2},
@@ -127,18 +143,24 @@ func Test_slashableAttestationCheck_OK(t *testing.T) {
}
sr := [32]byte{1}
fakePubkey := bytesutil.ToBytes48([]byte("test"))
mocks.slasherClient.EXPECT().IsSlashableAttestation(
gomock.Any(), // ctx
gomock.Any(),
).Return(&ethpb.AttesterSlashingResponse{}, nil /*err*/)
err := validator.slashableAttestationCheck(ctx, att, fakePubkey, sr)
require.NoError(t, err, "Expected allowed attestation not to throw error")
}
func Test_slashableAttestationCheck_GenesisEpoch(t *testing.T) {
config := &features.Flags{
RemoteSlasherProtection: false,
RemoteSlasherProtection: true,
}
reset := features.InitWithReset(config)
defer reset()
ctx := context.Background()
validator, _, _, finish := setup(t)
validator, mocks, _, finish := setup(t)
defer finish()
att := &ethpb.IndexedAttestation{
AttestingIndices: []uint64{1, 2},
@@ -156,6 +178,12 @@ func Test_slashableAttestationCheck_GenesisEpoch(t *testing.T) {
},
},
}
mocks.slasherClient.EXPECT().IsSlashableAttestation(
gomock.Any(), // ctx
gomock.Any(),
).Return(&ethpb.AttesterSlashingResponse{}, nil /*err*/)
fakePubkey := bytesutil.ToBytes48([]byte("test"))
err := validator.slashableAttestationCheck(ctx, att, fakePubkey, [32]byte{})
require.NoError(t, err, "Expected allowed attestation not to throw error")

View File

@@ -36,7 +36,6 @@ type Validator interface {
WaitForChainStart(ctx context.Context) error
WaitForSync(ctx context.Context) error
WaitForActivation(ctx context.Context, accountsChangedChan chan [][48]byte) error
SlasherReady(ctx context.Context) error
CanonicalHeadSlot(ctx context.Context) (types.Slot, error)
NextSlot() <-chan types.Slot
SlotDeadline(slot types.Slot) time.Time

View File

@@ -119,20 +119,13 @@ func (v *validator) proposeBlockPhase0(ctx context.Context, slot types.Slot, pub
return
}
if err := v.preBlockSignValidations(ctx, pubKey, wrapper.WrappedPhase0BeaconBlock(b), signingRoot); err != nil {
if err := v.slashableProposalCheck(ctx, pubKey, wrapper.WrappedPhase0SignedBeaconBlock(blk), signingRoot); err != nil {
log.WithFields(
blockLogFields(pubKey, wrapper.WrappedPhase0BeaconBlock(b), nil),
).WithError(err).Error("Failed block slashing protection check")
return
}
if err := v.postBlockSignUpdate(ctx, pubKey, wrapper.WrappedPhase0SignedBeaconBlock(blk), signingRoot); err != nil {
log.WithFields(
blockLogFields(pubKey, wrapper.WrappedPhase0BeaconBlock(b), sig),
).WithError(err).Error("Failed block slashing protection check")
return
}
// Propose and broadcast block via beacon node
blkResp, err := v.validatorClient.ProposeBlock(ctx, blk)
if err != nil {
@@ -252,16 +245,6 @@ func (v *validator) proposeBlockAltair(ctx context.Context, slot types.Slot, pub
return
}
if err := v.preBlockSignValidations(ctx, pubKey, wb, signingRoot); err != nil {
log.WithFields(
blockLogFields(pubKey, wb, nil),
).WithError(err).Error("Failed block slashing protection check")
if v.emitAccountMetrics {
ValidatorProposeFailVec.WithLabelValues(fmtKey).Inc()
}
return
}
wsb, err := wrapper.WrappedAltairSignedBeaconBlock(blk)
if err != nil {
log.WithError(err).Error("Failed to wrap signed block")
@@ -270,9 +253,10 @@ func (v *validator) proposeBlockAltair(ctx context.Context, slot types.Slot, pub
}
return
}
if err := v.postBlockSignUpdate(ctx, pubKey, wsb, signingRoot); err != nil {
if err := v.slashableProposalCheck(ctx, pubKey, wsb, signingRoot); err != nil {
log.WithFields(
blockLogFields(pubKey, wb, sig),
blockLogFields(pubKey, wb, nil),
).WithError(err).Error("Failed block slashing protection check")
if v.emitAccountMetrics {
ValidatorProposeFailVec.WithLabelValues(fmtKey).Inc()

View File

@@ -5,22 +5,23 @@ import (
"fmt"
"github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/beacon-chain/core/blocks"
"github.com/prysmaticlabs/prysm/config/features"
"github.com/prysmaticlabs/prysm/config/params"
"github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/block"
"github.com/sirupsen/logrus"
)
var failedPreBlockSignLocalErr = "attempted to sign a double proposal, block rejected by local protection"
var failedPreBlockSignExternalErr = "attempted a double proposal, block rejected by remote slashing protection"
var failedPostBlockSignErr = "made a double proposal, considered slashable by remote slashing protection"
var failedBlockSignLocalErr = "attempted to sign a double proposal, block rejected by local protection"
var failedBlockSignExternalErr = "attempted a double proposal, block rejected by remote slashing protection"
func (v *validator) preBlockSignValidations(
ctx context.Context, pubKey [48]byte, blk block.BeaconBlock, signingRoot [32]byte,
func (v *validator) slashableProposalCheck(
ctx context.Context, pubKey [48]byte, signedBlock block.SignedBeaconBlock, signingRoot [32]byte,
) error {
fmtKey := fmt.Sprintf("%#x", pubKey[:])
prevSigningRoot, proposalAtSlotExists, err := v.db.ProposalHistoryForSlot(ctx, pubKey, blk.Slot())
block := signedBlock.Block()
prevSigningRoot, proposalAtSlotExists, err := v.db.ProposalHistoryForSlot(ctx, pubKey, block.Slot())
if err != nil {
if v.emitAccountMetrics {
ValidatorProposeFailVec.WithLabelValues(fmtKey).Inc()
@@ -42,7 +43,7 @@ func (v *validator) preBlockSignValidations(
if v.emitAccountMetrics {
ValidatorProposeFailVec.WithLabelValues(fmtKey).Inc()
}
return errors.New(failedPreBlockSignLocalErr)
return errors.New(failedBlockSignLocalErr)
}
// Based on EIP3076, validator should refuse to sign any proposal with slot less
@@ -56,29 +57,24 @@ func (v *validator) preBlockSignValidations(
blk.Slot(),
)
}
return nil
}
func (v *validator) postBlockSignUpdate(
ctx context.Context,
pubKey [48]byte,
blk block.SignedBeaconBlock,
signingRoot [32]byte,
) error {
fmtKey := fmt.Sprintf("%#x", pubKey[:])
if features.Get().RemoteSlasherProtection && v.protector != nil {
blockHdr, err := block.SignedBeaconBlockHeaderFromBlockInterface(blk)
if features.Get().RemoteSlasherProtection {
blockHdr, err := blocks.SignedBeaconBlockHeaderFromBlockInterface(signedBlock)
if err != nil {
return errors.Wrap(err, "failed to get block header from block")
}
if !v.protector.CheckBlockSafety(ctx, blockHdr) {
slashing, err := v.slashingProtectionClient.IsSlashableBlock(ctx, blockHdr)
if err != nil {
return errors.Wrap(err, "could not check if block is slashable")
}
if slashing != nil && len(slashing.ProposerSlashings) > 0 {
if v.emitAccountMetrics {
ValidatorProposeFailVecSlasher.WithLabelValues(fmtKey).Inc()
}
return errors.New(failedPostBlockSignErr)
return errors.New(failedBlockSignExternalErr)
}
}
if err := v.db.SaveProposalHistoryForSlot(ctx, pubKey, blk.Block().Slot(), signingRoot[:]); err != nil {
if err := v.db.SaveProposalHistoryForSlot(ctx, pubKey, block.Slot(), signingRoot[:]); err != nil {
if v.emitAccountMetrics {
ValidatorProposeFailVec.WithLabelValues(fmtKey).Inc()
}

View File

@@ -4,8 +4,10 @@ import (
"context"
"testing"
"github.com/golang/mock/gomock"
types "github.com/prysmaticlabs/eth2-types"
"github.com/prysmaticlabs/prysm/config/features"
"github.com/prysmaticlabs/prysm/config/params"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/wrapper"
"github.com/prysmaticlabs/prysm/testing/require"
@@ -13,7 +15,7 @@ import (
mockSlasher "github.com/prysmaticlabs/prysm/validator/testing"
)
func TestPreBlockSignLocalValidation_PreventsLowerThanMinProposal(t *testing.T) {
func Test_slashableProposalCheck_PreventsLowerThanMinProposal(t *testing.T) {
ctx := context.Background()
validator, _, validatorKey, finish := setup(t)
defer finish()
@@ -28,55 +30,64 @@ func TestPreBlockSignLocalValidation_PreventsLowerThanMinProposal(t *testing.T)
// We expect the same block with a slot lower than the lowest
// signed slot to fail validation.
block := &ethpb.BeaconBlock{
Slot: lowestSignedSlot - 1,
ProposerIndex: 0,
block := &ethpb.SignedBeaconBlock{
Block: &ethpb.BeaconBlock{
Slot: lowestSignedSlot - 1,
ProposerIndex: 0,
},
Signature: params.BeaconConfig().EmptySignature[:],
}
err = validator.preBlockSignValidations(context.Background(), pubKeyBytes, wrapper.WrappedPhase0BeaconBlock(block), [32]byte{4})
err = validator.slashableProposalCheck(context.Background(), pubKeyBytes, wrapper.WrappedPhase0SignedBeaconBlock(block), [32]byte{4})
require.ErrorContains(t, "could not sign block with slot <= lowest signed", err)
// We expect the same block with a slot equal to the lowest
// signed slot to pass validation if signing roots are equal.
block = &ethpb.BeaconBlock{
Slot: lowestSignedSlot,
ProposerIndex: 0,
block = &ethpb.SignedBeaconBlock{
Block: &ethpb.BeaconBlock{
Slot: lowestSignedSlot,
ProposerIndex: 0,
},
Signature: params.BeaconConfig().EmptySignature[:],
}
err = validator.preBlockSignValidations(context.Background(), pubKeyBytes, wrapper.WrappedPhase0BeaconBlock(block), [32]byte{1})
err = validator.slashableProposalCheck(context.Background(), pubKeyBytes, wrapper.WrappedPhase0SignedBeaconBlock(block), [32]byte{1})
require.NoError(t, err)
// We expect the same block with a slot equal to the lowest
// signed slot to fail validation if signing roots are different.
block = &ethpb.BeaconBlock{
Slot: lowestSignedSlot,
ProposerIndex: 0,
}
err = validator.preBlockSignValidations(context.Background(), pubKeyBytes, wrapper.WrappedPhase0BeaconBlock(block), [32]byte{4})
require.ErrorContains(t, failedPreBlockSignLocalErr, err)
err = validator.slashableProposalCheck(context.Background(), pubKeyBytes, wrapper.WrappedPhase0SignedBeaconBlock(block), [32]byte{4})
require.ErrorContains(t, failedBlockSignLocalErr, err)
// We expect the same block with a slot > than the lowest
// signed slot to pass validation.
block = &ethpb.BeaconBlock{
Slot: lowestSignedSlot + 1,
ProposerIndex: 0,
block = &ethpb.SignedBeaconBlock{
Block: &ethpb.BeaconBlock{
Slot: lowestSignedSlot + 1,
ProposerIndex: 0,
},
Signature: params.BeaconConfig().EmptySignature[:],
}
err = validator.preBlockSignValidations(context.Background(), pubKeyBytes, wrapper.WrappedPhase0BeaconBlock(block), [32]byte{3})
err = validator.slashableProposalCheck(context.Background(), pubKeyBytes, wrapper.WrappedPhase0SignedBeaconBlock(block), [32]byte{3})
require.NoError(t, err)
}
func TestPreBlockSignLocalValidation(t *testing.T) {
func Test_slashableProposalCheck(t *testing.T) {
ctx := context.Background()
config := &features.Flags{
RemoteSlasherProtection: false,
RemoteSlasherProtection: true,
}
reset := features.InitWithReset(config)
defer reset()
validator, _, validatorKey, finish := setup(t)
validator, mocks, validatorKey, finish := setup(t)
defer finish()
block := &ethpb.BeaconBlock{
Slot: 10,
ProposerIndex: 0,
}
block := util.HydrateSignedBeaconBlock(&ethpb.SignedBeaconBlock{
Block: &ethpb.BeaconBlock{
Slot: 10,
ProposerIndex: 0,
},
Signature: params.BeaconConfig().EmptySignature[:],
})
pubKeyBytes := [48]byte{}
copy(pubKeyBytes[:], validatorKey.PublicKey().Marshal())
@@ -91,64 +102,63 @@ func TestPreBlockSignLocalValidation(t *testing.T) {
pubKey := [48]byte{}
copy(pubKey[:], validatorKey.PublicKey().Marshal())
mock.slasherClient.EXPECT().IsSlashableBlock(
gomock.Any(), // ctx
gomock.Any(),
).Times(2).Return(&ethpb.ProposerSlashingResponse{}, nil /*err*/)
// We expect the same block sent out with the same root should not be slasahble.
err = validator.preBlockSignValidations(context.Background(), pubKey, wrapper.WrappedPhase0BeaconBlock(block), dummySigningRoot)
err = validator.slashableProposalCheck(context.Background(), pubKey, wrapper.WrappedPhase0SignedBeaconBlock(block), dummySigningRoot)
require.NoError(t, err)
// We expect the same block sent out with a different signing root should be slasahble.
err = validator.preBlockSignValidations(context.Background(), pubKey, wrapper.WrappedPhase0BeaconBlock(block), [32]byte{2})
require.ErrorContains(t, failedPreBlockSignLocalErr, err)
err = validator.slashableProposalCheck(context.Background(), pubKey, wrapper.WrappedPhase0SignedBeaconBlock(block), [32]byte{2})
require.ErrorContains(t, failedBlockSignLocalErr, err)
// We save a proposal at slot 11 with a nil signing root.
block.Slot = 11
err = validator.db.SaveProposalHistoryForSlot(ctx, pubKeyBytes, block.Slot, nil)
block.Block.Slot = 11
err = validator.db.SaveProposalHistoryForSlot(ctx, pubKeyBytes, block.Block.Slot, nil)
require.NoError(t, err)
// We expect the same block sent out should return slashable error even
// if we had a nil signing root stored in the database.
err = validator.preBlockSignValidations(context.Background(), pubKey, wrapper.WrappedPhase0BeaconBlock(block), [32]byte{2})
require.ErrorContains(t, failedPreBlockSignLocalErr, err)
err = validator.slashableProposalCheck(context.Background(), pubKey, wrapper.WrappedPhase0SignedBeaconBlock(block), [32]byte{2})
require.ErrorContains(t, failedBlockSignLocalErr, err)
// A block with a different slot for which we do not have a proposing history
// should not be failing validation.
block.Slot = 9
err = validator.preBlockSignValidations(context.Background(), pubKey, wrapper.WrappedPhase0BeaconBlock(block), [32]byte{3})
block.Block.Slot = 9
err = validator.slashableProposalCheck(context.Background(), pubKey, wrapper.WrappedPhase0SignedBeaconBlock(block), [32]byte{3})
require.NoError(t, err, "Expected allowed block not to throw error")
}
func TestPreBlockSignValidation(t *testing.T) {
validator, _, validatorKey, finish := setup(t)
func Test_slashableProposalCheck_RemoteProtection(t *testing.T) {
config := &features.Flags{
RemoteSlasherProtection: true,
}
reset := features.InitWithReset(config)
defer reset()
validator, m, validatorKey, finish := setup(t)
defer finish()
pubKey := [48]byte{}
copy(pubKey[:], validatorKey.PublicKey().Marshal())
block := util.NewBeaconBlock()
block.Block.Slot = 10
mockProtector := &mockSlasher.MockProtector{AllowBlock: false}
validator.protector = mockProtector
mockProtector.AllowBlock = true
err := validator.preBlockSignValidations(context.Background(), pubKey, wrapper.WrappedPhase0BeaconBlock(block.Block), [32]byte{2})
require.NoError(t, err, "Expected allowed block not to throw error")
}
func TestPostBlockSignUpdate(t *testing.T) {
config := &features.Flags{
RemoteSlasherProtection: true,
}
reset := features.InitWithReset(config)
defer reset()
validator, _, validatorKey, finish := setup(t)
defer finish()
pubKey := [48]byte{}
copy(pubKey[:], validatorKey.PublicKey().Marshal())
emptyBlock := util.NewBeaconBlock()
emptyBlock.Block.Slot = 10
emptyBlock.Block.ProposerIndex = 0
mockProtector := &mockSlasher.MockProtector{AllowBlock: false}
validator.protector = mockProtector
err := validator.postBlockSignUpdate(context.Background(), pubKey, wrapper.WrappedPhase0SignedBeaconBlock(emptyBlock), [32]byte{})
require.ErrorContains(t, failedPostBlockSignErr, err, "Expected error when post signature update is detected as slashable")
mockProtector.AllowBlock = true
err = validator.postBlockSignUpdate(context.Background(), pubKey, wrapper.WrappedPhase0SignedBeaconBlock(emptyBlock), [32]byte{})
m.nodeClient.EXPECT().IsSlashableBlock(
gomock.Any(), // ctx
gomock.Any(),
).Return(&ethpb.ProposerSlashingResponse{ProposerSlashings: []*ethpb.ProposerSlashing{{}}}, nil /*err*/)
err := validator.slashableProposalCheck(context.Background(), pubKey, wrapper.WrappedPhase0SignedBeaconBlock(block), [32]byte{2})
require.ErrorContains(t, failedBlockSignExternalErr, err)
m.slasherClient.EXPECT().IsSlashableBlock(
gomock.Any(), // ctx
gomock.Any(),
).Return(&ethpb.ProposerSlashingResponse{}, nil /*err*/)
err = validator.slashableProposalCheck(context.Background(), pubKey, wrapper.WrappedPhase0SignedBeaconBlock(block), [32]byte{2})
require.NoError(t, err, "Expected allowed block not to throw error")
}

View File

@@ -296,10 +296,10 @@ func TestProposeBlock_BlocksDoubleProposal(t *testing.T) {
).Return(&ethpb.ProposeResponse{BlockRoot: make([]byte, 32)}, nil /*error*/)
validator.ProposeBlock(context.Background(), slot, pubKey)
require.LogsDoNotContain(t, hook, failedPreBlockSignLocalErr)
require.LogsDoNotContain(t, hook, failedBlockSignLocalErr)
validator.ProposeBlock(context.Background(), slot, pubKey)
require.LogsContain(t, hook, failedPreBlockSignLocalErr)
require.LogsContain(t, hook, failedBlockSignLocalErr)
}
func TestProposeBlockAltair_BlocksDoubleProposal(t *testing.T) {
@@ -356,10 +356,10 @@ func TestProposeBlockAltair_BlocksDoubleProposal(t *testing.T) {
).Return(&ethpb.ProposeResponse{BlockRoot: make([]byte, 32)}, nil /*error*/)
validator.ProposeBlock(context.Background(), slot, pubKey)
require.LogsDoNotContain(t, hook, failedPreBlockSignLocalErr)
require.LogsDoNotContain(t, hook, failedBlockSignLocalErr)
validator.ProposeBlock(context.Background(), slot, pubKey)
require.LogsContain(t, hook, failedPreBlockSignLocalErr)
require.LogsContain(t, hook, failedBlockSignLocalErr)
}
func TestProposeBlock_BlocksDoubleProposal_After54KEpochs(t *testing.T) {
@@ -408,10 +408,10 @@ func TestProposeBlock_BlocksDoubleProposal_After54KEpochs(t *testing.T) {
).Return(&ethpb.ProposeResponse{BlockRoot: make([]byte, 32)}, nil /*error*/)
validator.ProposeBlock(context.Background(), farFuture, pubKey)
require.LogsDoNotContain(t, hook, failedPreBlockSignLocalErr)
require.LogsDoNotContain(t, hook, failedBlockSignLocalErr)
validator.ProposeBlock(context.Background(), farFuture, pubKey)
require.LogsContain(t, hook, failedPreBlockSignLocalErr)
require.LogsContain(t, hook, failedBlockSignLocalErr)
}
func TestProposeBlock_AllowsPastProposals(t *testing.T) {
@@ -449,7 +449,7 @@ func TestProposeBlock_AllowsPastProposals(t *testing.T) {
).Times(2).Return(&ethpb.ProposeResponse{BlockRoot: make([]byte, 32)}, nil /*error*/)
validator.ProposeBlock(context.Background(), farAhead, pubKey)
require.LogsDoNotContain(t, hook, failedPreBlockSignLocalErr)
require.LogsDoNotContain(t, hook, failedBlockSignLocalErr)
past := params.BeaconConfig().SlotsPerEpoch.Mul(uint64(params.BeaconConfig().WeakSubjectivityPeriod - 400))
blk2 := util.NewBeaconBlock()
@@ -459,7 +459,7 @@ func TestProposeBlock_AllowsPastProposals(t *testing.T) {
gomock.Any(),
).Return(blk2.Block, nil /*err*/)
validator.ProposeBlock(context.Background(), past, pubKey)
require.LogsDoNotContain(t, hook, failedPreBlockSignLocalErr)
require.LogsDoNotContain(t, hook, failedBlockSignLocalErr)
}
func TestProposeBlock_AllowsSameEpoch(t *testing.T) {
@@ -497,7 +497,7 @@ func TestProposeBlock_AllowsSameEpoch(t *testing.T) {
).Times(2).Return(&ethpb.ProposeResponse{BlockRoot: make([]byte, 32)}, nil /*error*/)
validator.ProposeBlock(context.Background(), farAhead, pubKey)
require.LogsDoNotContain(t, hook, failedPreBlockSignLocalErr)
require.LogsDoNotContain(t, hook, failedBlockSignLocalErr)
blk2 := util.NewBeaconBlock()
blk2.Block.Slot = farAhead - 4
@@ -507,7 +507,7 @@ func TestProposeBlock_AllowsSameEpoch(t *testing.T) {
).Return(blk2.Block, nil /*err*/)
validator.ProposeBlock(context.Background(), farAhead-4, pubKey)
require.LogsDoNotContain(t, hook, failedPreBlockSignLocalErr)
require.LogsDoNotContain(t, hook, failedBlockSignLocalErr)
}
func TestProposeBlock_BroadcastsBlock(t *testing.T) {

View File

@@ -9,7 +9,6 @@ import (
"github.com/pkg/errors"
types "github.com/prysmaticlabs/eth2-types"
"github.com/prysmaticlabs/prysm/beacon-chain/core"
"github.com/prysmaticlabs/prysm/config/features"
"github.com/prysmaticlabs/prysm/config/params"
"github.com/prysmaticlabs/prysm/encoding/bytesutil"
"github.com/prysmaticlabs/prysm/validator/client/iface"
@@ -40,11 +39,6 @@ func run(ctx context.Context, v iface.Validator) {
cleanup()
log.Fatalf("Wallet is not ready: %v", err)
}
if features.Get().RemoteSlasherProtection {
if err := v.SlasherReady(ctx); err != nil {
log.Fatalf("Slasher is not ready: %v", err)
}
}
ticker := time.NewTicker(backOffPeriod)
defer ticker.Stop()

View File

@@ -8,7 +8,6 @@ import (
types "github.com/prysmaticlabs/eth2-types"
"github.com/prysmaticlabs/prysm/async/event"
"github.com/prysmaticlabs/prysm/config/features"
"github.com/prysmaticlabs/prysm/testing/assert"
"github.com/prysmaticlabs/prysm/testing/require"
"github.com/prysmaticlabs/prysm/validator/client/iface"
@@ -62,17 +61,6 @@ func TestCancelledContext_WaitsForActivation(t *testing.T) {
assert.Equal(t, 1, v.WaitForActivationCalled, "Expected WaitForActivation() to be called")
}
func TestCancelledContext_ChecksSlasherReady(t *testing.T) {
v := &testutil.FakeValidator{Keymanager: &mockKeymanager{accountsChangedFeed: &event.Feed{}}}
cfg := &features.Flags{
RemoteSlasherProtection: true,
}
reset := features.InitWithReset(cfg)
defer reset()
run(cancelledContext(), v)
assert.Equal(t, true, v.SlasherReadyCalled, "Expected SlasherReady() to be called")
}
func TestUpdateDuties_NextSlot(t *testing.T) {
v := &testutil.FakeValidator{Keymanager: &mockKeymanager{accountsChangedFeed: &event.Feed{}}}
ctx, cancel := context.WithCancel(context.Background())

View File

@@ -27,7 +27,6 @@ import (
"github.com/prysmaticlabs/prysm/validator/graffiti"
"github.com/prysmaticlabs/prysm/validator/keymanager"
"github.com/prysmaticlabs/prysm/validator/keymanager/imported"
slashingiface "github.com/prysmaticlabs/prysm/validator/slashing-protection/iface"
"go.opencensus.io/plugin/ocgrpc"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
@@ -64,7 +63,6 @@ type ValidatorService struct {
withCert string
endpoint string
validator iface.Validator
protector slashingiface.Protector
ctx context.Context
keyManager keymanager.IKeymanager
grpcHeaders []string
@@ -82,7 +80,6 @@ type Config struct {
GrpcRetriesFlag uint
GrpcRetryDelay time.Duration
GrpcMaxCallRecvMsgSizeFlag int
Protector slashingiface.Protector
Endpoint string
Validator iface.Validator
ValDB db.Database
@@ -112,7 +109,6 @@ func NewValidatorService(ctx context.Context, cfg *Config) (*ValidatorService, e
grpcRetries: cfg.GrpcRetriesFlag,
grpcRetryDelay: cfg.GrpcRetryDelay,
grpcHeaders: strings.Split(cfg.GrpcHeadersFlag, ","),
protector: cfg.Protector,
validator: cfg.Validator,
db: cfg.ValDB,
walletInitializedFeed: cfg.WalletInitializedFeed,
@@ -188,7 +184,6 @@ func (v *ValidatorService) Start() {
attLogs: make(map[[32]byte]*attSubmitted),
domainDataCache: cache,
aggregatedSlotCommitteeIDCache: aggregatedSlotCommitteeIDCache,
protector: v.protector,
voteStats: voteStats{startEpoch: types.Epoch(^uint64(0))},
useWeb: v.useWeb,
walletInitializedFeed: v.walletInitializedFeed,

View File

@@ -9,7 +9,6 @@ import (
"testing"
"github.com/bazelbuild/rules_go/go/tools/bazel"
"github.com/prysmaticlabs/prysm/config/features"
"github.com/prysmaticlabs/prysm/io/file"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/wrapper"
@@ -76,12 +75,6 @@ func setupEIP3076SpecTests(t *testing.T) []*eip3076TestCase {
}
func TestEIP3076SpecTests(t *testing.T) {
config := &features.Flags{
RemoteSlasherProtection: true,
}
reset := features.InitWithReset(config)
defer reset()
testCases := setupEIP3076SpecTests(t)
for _, tt := range testCases {
t.Run(tt.Name, func(t *testing.T) {
@@ -130,22 +123,12 @@ func TestEIP3076SpecTests(t *testing.T) {
copy(signingRoot[:], signingRootBytes)
}
err = validator.preBlockSignValidations(context.Background(), pk, wrapper.WrappedPhase0BeaconBlock(b.Block), signingRoot)
err = validator.slashableProposalCheck(context.Background(), pk, wrapper.WrappedPhase0SignedBeaconBlock(b), signingRoot)
if sb.ShouldSucceed {
require.NoError(t, err)
} else {
require.NotEqual(t, nil, err, "pre validation should have failed for block")
}
// Only proceed post update if pre validation did not error.
if err == nil {
err = validator.postBlockSignUpdate(context.Background(), pk, wrapper.WrappedPhase0SignedBeaconBlock(b), signingRoot)
if sb.ShouldSucceed {
require.NoError(t, err)
} else {
require.NotEqual(t, nil, err, "post validation should have failed for block")
}
}
}
// This loops through a list of attestation signings to attempt after importing the interchange data above.

View File

@@ -36,20 +36,17 @@ import (
"github.com/prysmaticlabs/prysm/validator/db/kv"
"github.com/prysmaticlabs/prysm/validator/graffiti"
"github.com/prysmaticlabs/prysm/validator/keymanager"
slashingiface "github.com/prysmaticlabs/prysm/validator/slashing-protection/iface"
"github.com/sirupsen/logrus"
"go.opencensus.io/trace"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/emptypb"
)
// reconnectPeriod is the frequency that we try to restart our
// slasher connection when the slasher client connection is not ready.
var reconnectPeriod = 5 * time.Second
// keyFetchPeriod is the frequency that we try to refetch validating keys
// in case no keys were fetched previously.
var keyRefetchPeriod = 30 * time.Second
var (
keyRefetchPeriod = 30 * time.Second
)
var (
msgCouldNotFetchKeys = "could not fetch validating keys"
@@ -81,7 +78,7 @@ type validator struct {
keyManager keymanager.IKeymanager
beaconClient ethpb.BeaconChainClient
validatorClient ethpb.BeaconNodeValidatorClient
protector slashingiface.Protector
slashingProtectionClient ethpb.SlasherClient
db vdb.Database
graffiti []byte
voteStats voteStats
@@ -224,6 +221,8 @@ func (v *validator) WaitForSync(ctx context.Context) error {
}
}
<<<<<<< HEAD
=======
// SlasherReady checks if slasher that was configured as external protection
// is reachable.
func (v *validator) SlasherReady(ctx context.Context) error {
@@ -255,6 +254,7 @@ func (v *validator) SlasherReady(ctx context.Context) error {
return nil
}
>>>>>>> develop
// ReceiveBlocks starts a gRPC client stream listener to obtain
// blocks from the beacon node. Upon receiving a block, the service
// broadcasts it to a feed for other usages to subscribe to.

View File

@@ -52,8 +52,6 @@ go_library(
"//validator/keymanager:go_default_library",
"//validator/keymanager/imported:go_default_library",
"//validator/rpc:go_default_library",
"//validator/slashing-protection:go_default_library",
"//validator/slashing-protection/iface:go_default_library",
"//validator/web:go_default_library",
"@com_github_grpc_ecosystem_grpc_gateway_v2//runtime:go_default_library",
"@com_github_pkg_errors//:go_default_library",

View File

@@ -40,8 +40,6 @@ import (
"github.com/prysmaticlabs/prysm/validator/keymanager"
"github.com/prysmaticlabs/prysm/validator/keymanager/imported"
"github.com/prysmaticlabs/prysm/validator/rpc"
slashingprotection "github.com/prysmaticlabs/prysm/validator/slashing-protection"
"github.com/prysmaticlabs/prysm/validator/slashing-protection/iface"
"github.com/prysmaticlabs/prysm/validator/web"
"github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"
@@ -251,9 +249,6 @@ func (c *ValidatorClient) initializeFromCLI(cliCtx *cli.Context) error {
return err
}
}
if err := c.registerSlasherService(); err != nil {
return err
}
if err := c.registerValidatorService(keyManager); err != nil {
return err
}
@@ -338,9 +333,6 @@ func (c *ValidatorClient) initializeForWeb(cliCtx *cli.Context) error {
return err
}
}
if err := c.registerSlasherService(); err != nil {
return err
}
if err := c.registerValidatorService(keyManager); err != nil {
return err
}
@@ -391,12 +383,6 @@ func (c *ValidatorClient) registerValidatorService(
maxCallRecvMsgSize := c.cliCtx.Int(cmd.GrpcMaxCallRecvMsgSizeFlag.Name)
grpcRetries := c.cliCtx.Uint(flags.GrpcRetriesFlag.Name)
grpcRetryDelay := c.cliCtx.Duration(flags.GrpcRetryDelayFlag.Name)
var sp *slashingprotection.Service
var protector iface.Protector
if err := c.services.FetchService(&sp); err == nil {
protector = sp
}
gStruct := &g.Graffiti{}
var err error
if c.cliCtx.IsSet(flags.GraffitiFileFlag.Name) {
@@ -419,7 +405,6 @@ func (c *ValidatorClient) registerValidatorService(
GrpcRetriesFlag: grpcRetries,
GrpcRetryDelay: grpcRetryDelay,
GrpcHeadersFlag: c.cliCtx.String(flags.GrpcHeadersFlag.Name),
Protector: protector,
ValDB: c.db,
UseWeb: c.cliCtx.Bool(flags.EnableWebFlag.Name),
WalletInitializedFeed: c.walletInitialized,
@@ -432,32 +417,6 @@ func (c *ValidatorClient) registerValidatorService(
return c.services.RegisterService(v)
}
func (c *ValidatorClient) registerSlasherService() error {
if !features.Get().RemoteSlasherProtection {
return nil
}
endpoint := c.cliCtx.String(flags.SlasherRPCProviderFlag.Name)
if endpoint == "" {
return errors.New("external slasher feature flag is set but no slasher endpoint is configured")
}
cert := c.cliCtx.String(flags.SlasherCertFlag.Name)
maxCallRecvMsgSize := c.cliCtx.Int(cmd.GrpcMaxCallRecvMsgSizeFlag.Name)
grpcRetries := c.cliCtx.Uint(flags.GrpcRetriesFlag.Name)
grpcRetryDelay := c.cliCtx.Duration(flags.GrpcRetryDelayFlag.Name)
sp, err := slashingprotection.NewService(c.cliCtx.Context, &slashingprotection.Config{
Endpoint: endpoint,
CertFlag: cert,
GrpcMaxCallRecvMsgSizeFlag: maxCallRecvMsgSize,
GrpcRetriesFlag: grpcRetries,
GrpcRetryDelay: grpcRetryDelay,
GrpcHeadersFlag: c.cliCtx.String(flags.GrpcHeadersFlag.Name),
})
if err != nil {
return errors.Wrap(err, "could not initialize slasher service")
}
return c.services.RegisterService(sp)
}
func (c *ValidatorClient) registerRPCService(cliCtx *cli.Context, km keymanager.IKeymanager) error {
var vs *client.ValidatorService

View File

@@ -5,9 +5,7 @@ go_library(
srcs = [
"cli_export.go",
"cli_import.go",
"external.go",
"log.go",
"slasher_client.go",
],
importpath = "github.com/prysmaticlabs/prysm/validator/slashing-protection",
visibility = [
@@ -15,35 +13,21 @@ go_library(
"//validator:__subpackages__",
],
deps = [
"//api/grpc:go_default_library",
"//cmd:go_default_library",
"//cmd/validator/flags:go_default_library",
"//io/file:go_default_library",
"//proto/prysm/v1alpha1:go_default_library",
"//validator/accounts/userprompt:go_default_library",
"//validator/db/kv:go_default_library",
"//validator/slashing-protection/local/standard-protection-format:go_default_library",
"@com_github_grpc_ecosystem_go_grpc_middleware//:go_default_library",
"@com_github_grpc_ecosystem_go_grpc_middleware//retry:go_default_library",
"@com_github_grpc_ecosystem_go_grpc_middleware//tracing/opentracing:go_default_library",
"@com_github_grpc_ecosystem_go_grpc_prometheus//:go_default_library",
"@com_github_pkg_errors//:go_default_library",
"@com_github_sirupsen_logrus//:go_default_library",
"@com_github_urfave_cli_v2//:go_default_library",
"@io_opencensus_go//plugin/ocgrpc:go_default_library",
"@org_golang_google_grpc//:go_default_library",
"@org_golang_google_grpc//connectivity:go_default_library",
"@org_golang_google_grpc//credentials:go_default_library",
],
)
go_test(
name = "go_default_test",
srcs = [
"cli_import_export_test.go",
"external_test.go",
"slasher_client_test.go",
],
srcs = ["cli_import_export_test.go"],
embed = [":go_default_library"],
deps = [
"//cmd:go_default_library",
@@ -51,7 +35,6 @@ go_test(
"//config/params:go_default_library",
"//encoding/bytesutil:go_default_library",
"//io/file:go_default_library",
"//proto/prysm/v1alpha1:go_default_library",
"//testing/assert:go_default_library",
"//testing/require:go_default_library",
"//validator/db/kv:go_default_library",
@@ -59,6 +42,5 @@ go_test(
"//validator/slashing-protection/local/standard-protection-format/format:go_default_library",
"//validator/testing:go_default_library",
"@com_github_urfave_cli_v2//:go_default_library",
"@org_golang_google_grpc//metadata:go_default_library",
],
)

View File

@@ -1,35 +0,0 @@
package slashingprotection
import (
"context"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
)
// CheckBlockSafety for blocks before submitting them to the node.
func (s *Service) CheckBlockSafety(ctx context.Context, blockHeader *ethpb.SignedBeaconBlockHeader) bool {
ps, err := s.slasherClient.IsSlashableBlock(ctx, blockHeader)
if err != nil {
log.Errorf("External slashing block protection returned an error: %v", err)
return false
}
if ps != nil && len(ps.ProposerSlashings) != 0 {
log.Warn("External slashing proposal protection found the block to be slashable")
return false
}
return true
}
// CheckAttestationSafety for attestations before submitting them to the node.
func (s *Service) CheckAttestationSafety(ctx context.Context, attestation *ethpb.IndexedAttestation) bool {
as, err := s.slasherClient.IsSlashableAttestation(ctx, attestation)
if err != nil {
log.Errorf("External slashing attestation protection returned an error: %v", err)
return false
}
if as != nil && len(as.AttesterSlashings) != 0 {
log.Warnf("External slashing attestation protection found the attestation to be slashable: %v", as)
return false
}
return true
}

View File

@@ -1,50 +0,0 @@
package slashingprotection
import (
"context"
"testing"
"github.com/prysmaticlabs/prysm/config/params"
"github.com/prysmaticlabs/prysm/encoding/bytesutil"
eth "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/testing/assert"
mockSlasher "github.com/prysmaticlabs/prysm/validator/testing"
)
func TestService_VerifyAttestation(t *testing.T) {
s := &Service{slasherClient: mockSlasher.MockSlasher{SlashAttestation: true}}
att := &eth.IndexedAttestation{
AttestingIndices: []uint64{1, 2},
Data: &eth.AttestationData{
Slot: 5,
CommitteeIndex: 2,
BeaconBlockRoot: []byte("great block"),
Source: &eth.Checkpoint{
Epoch: 4,
Root: []byte("good source"),
},
Target: &eth.Checkpoint{
Epoch: 10,
Root: []byte("good target"),
},
},
}
assert.Equal(t, false, s.CheckAttestationSafety(context.Background(), att), "Expected verify attestation to fail verification")
s = &Service{slasherClient: mockSlasher.MockSlasher{SlashAttestation: false}}
assert.Equal(t, true, s.CheckAttestationSafety(context.Background(), att), "Expected verify attestation to pass verification")
}
func TestService_VerifyBlock(t *testing.T) {
s := &Service{slasherClient: mockSlasher.MockSlasher{SlashBlock: true}}
blk := &eth.BeaconBlockHeader{
Slot: 0,
ProposerIndex: 0,
ParentRoot: bytesutil.PadTo([]byte("parent"), 32),
StateRoot: bytesutil.PadTo([]byte("state"), 32),
BodyRoot: bytesutil.PadTo([]byte("body"), 32),
}
sblk := &eth.SignedBeaconBlockHeader{Header: blk, Signature: params.BeaconConfig().EmptySignature[:]}
assert.Equal(t, false, s.CheckBlockSafety(context.Background(), sblk), "Expected verify block to fail verification")
s = &Service{slasherClient: mockSlasher.MockSlasher{SlashBlock: false}}
assert.Equal(t, true, s.CheckBlockSafety(context.Background(), sblk), "Expected verify block to pass verification")
}

View File

@@ -1,9 +0,0 @@
load("@prysm//tools/go:def.bzl", "go_library")
go_library(
name = "go_default_library",
srcs = ["protector.go"],
importpath = "github.com/prysmaticlabs/prysm/validator/slashing-protection/iface",
visibility = ["//validator:__subpackages__"],
deps = ["//proto/prysm/v1alpha1:go_default_library"],
)

View File

@@ -1,14 +0,0 @@
package iface
import (
"context"
eth "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
)
// Protector interface defines the methods of the service that provides slashing protection.
type Protector interface {
CheckAttestationSafety(ctx context.Context, attestation *eth.IndexedAttestation) bool
CheckBlockSafety(ctx context.Context, blockHeader *eth.SignedBeaconBlockHeader) bool
Status() error
}

View File

@@ -1,129 +0,0 @@
package slashingprotection
import (
"context"
"errors"
"fmt"
"strings"
"time"
middleware "github.com/grpc-ecosystem/go-grpc-middleware"
grpc_retry "github.com/grpc-ecosystem/go-grpc-middleware/retry"
grpc_opentracing "github.com/grpc-ecosystem/go-grpc-middleware/tracing/opentracing"
grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
grpcutil "github.com/prysmaticlabs/prysm/api/grpc"
ethsl "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
"go.opencensus.io/plugin/ocgrpc"
"google.golang.org/grpc"
"google.golang.org/grpc/connectivity"
"google.golang.org/grpc/credentials"
)
// Service represents a service to manage the validator
// ￿slashing protection.
type Service struct {
cfg *Config
ctx context.Context
cancel context.CancelFunc
conn *grpc.ClientConn
grpcHeaders []string
slasherClient ethsl.SlasherClient
}
// Config for the validator service.
type Config struct {
Endpoint string
CertFlag string
GrpcMaxCallRecvMsgSizeFlag int
GrpcRetriesFlag uint
GrpcRetryDelay time.Duration
GrpcHeadersFlag string
}
// NewService creates a new validator service for the service
// registry.
func NewService(ctx context.Context, cfg *Config) (*Service, error) {
ctx, cancel := context.WithCancel(ctx)
return &Service{
cfg: cfg,
ctx: ctx,
cancel: cancel,
grpcHeaders: strings.Split(cfg.GrpcHeadersFlag, ","),
}, nil
}
// Start the slasher protection service and grpc client.
func (s *Service) Start() {
if s.cfg.Endpoint != "" {
s.slasherClient = s.startSlasherClient()
}
}
func (s *Service) startSlasherClient() ethsl.SlasherClient {
var dialOpt grpc.DialOption
if s.cfg.CertFlag != "" {
creds, err := credentials.NewClientTLSFromFile(s.cfg.CertFlag, "")
if err != nil {
log.Errorf("Could not get valid slasher credentials: %v", err)
return nil
}
dialOpt = grpc.WithTransportCredentials(creds)
} else {
dialOpt = grpc.WithInsecure()
log.Warn("You are using an insecure slasher gRPC connection! Please provide a certificate and key to use a secure connection.")
}
s.ctx = grpcutil.AppendHeaders(s.ctx, s.grpcHeaders)
opts := []grpc.DialOption{
dialOpt,
grpc.WithDefaultCallOptions(
grpc_retry.WithMax(s.cfg.GrpcRetriesFlag),
grpc_retry.WithBackoff(grpc_retry.BackoffLinear(s.cfg.GrpcRetryDelay)),
),
grpc.WithStatsHandler(&ocgrpc.ClientHandler{}),
grpc.WithStreamInterceptor(middleware.ChainStreamClient(
grpc_opentracing.StreamClientInterceptor(),
grpc_prometheus.StreamClientInterceptor,
grpc_retry.StreamClientInterceptor(),
)),
grpc.WithUnaryInterceptor(middleware.ChainUnaryClient(
grpc_opentracing.UnaryClientInterceptor(),
grpc_prometheus.UnaryClientInterceptor,
grpc_retry.UnaryClientInterceptor(),
grpcutil.LogRequests,
)),
}
conn, err := grpc.DialContext(s.ctx, s.cfg.Endpoint, opts...)
if err != nil {
log.Errorf("Could not dial slasher endpoint: %s, %v", s.cfg.Endpoint, err)
return nil
}
log.Debug("Successfully started slasher gRPC connection")
s.conn = conn
return ethsl.NewSlasherClient(s.conn)
}
// Stop the validator service.
func (s *Service) Stop() error {
s.cancel()
log.Info("Stopping slashing protection service")
if s.conn != nil {
return s.conn.Close()
}
return nil
}
// Status checks if the connection to slasher server is ready,
// returns error otherwise.
func (s *Service) Status() error {
if s.conn == nil {
return errors.New("no connection to slasher RPC")
}
if s.conn.GetState() != connectivity.Ready {
return fmt.Errorf("can`t connect to slasher server at: %v connection status: %v ", s.cfg.Endpoint, s.conn.GetState())
}
return nil
}

View File

@@ -1,23 +0,0 @@
package slashingprotection
import (
"context"
"testing"
"github.com/prysmaticlabs/prysm/testing/assert"
"github.com/prysmaticlabs/prysm/testing/require"
"google.golang.org/grpc/metadata"
)
func TestGrpcHeaders(t *testing.T) {
s := &Service{
cfg: &Config{},
ctx: context.Background(),
grpcHeaders: []string{"first=value1", "second=value2"},
}
s.startSlasherClient()
md, _ := metadata.FromOutgoingContext(s.ctx)
require.Equal(t, 2, md.Len(), "MetadataV0 contains wrong number of values")
assert.Equal(t, "value1", md.Get("first")[0])
assert.Equal(t, "value2", md.Get("second")[0])
}