2020-02-14 18:11:15 +00:00
|
|
|
package beaconclient
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
|
|
|
"go.opencensus.io/trace"
|
|
|
|
)
|
|
|
|
|
|
|
|
// subscribeDetectedProposerSlashings subscribes to an event feed for
|
|
|
|
// slashing objects from the slasher runtime. Upon receiving
|
|
|
|
// a proposer slashing from the feed, we submit the object to the
|
|
|
|
// connected beacon node via a client RPC.
|
|
|
|
func (bs *Service) subscribeDetectedProposerSlashings(ctx context.Context, ch chan *ethpb.ProposerSlashing) {
|
|
|
|
ctx, span := trace.StartSpan(ctx, "beaconclient.submitProposerSlashing")
|
|
|
|
defer span.End()
|
2020-02-14 19:03:25 +00:00
|
|
|
sub := bs.proposerSlashingsFeed.Subscribe(ch)
|
|
|
|
defer sub.Unsubscribe()
|
2020-02-14 18:11:15 +00:00
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case slashing := <-ch:
|
2020-02-19 22:26:14 +00:00
|
|
|
if _, err := bs.beaconClient.SubmitProposerSlashing(ctx, slashing); err != nil {
|
2020-02-14 18:11:15 +00:00
|
|
|
log.Error(err)
|
|
|
|
}
|
2020-02-14 19:03:25 +00:00
|
|
|
case <-sub.Err():
|
|
|
|
log.Error("Subscriber closed, exiting goroutine")
|
2020-02-14 18:11:15 +00:00
|
|
|
return
|
|
|
|
case <-ctx.Done():
|
2020-02-14 19:03:25 +00:00
|
|
|
log.Error("Context canceled")
|
2020-02-14 18:11:15 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// subscribeDetectedAttesterSlashings subscribes to an event feed for
|
|
|
|
// slashing objects from the slasher runtime. Upon receiving an
|
|
|
|
// attester slashing from the feed, we submit the object to the
|
|
|
|
// connected beacon node via a client RPC.
|
|
|
|
func (bs *Service) subscribeDetectedAttesterSlashings(ctx context.Context, ch chan *ethpb.AttesterSlashing) {
|
|
|
|
ctx, span := trace.StartSpan(ctx, "beaconclient.submitAttesterSlashing")
|
|
|
|
defer span.End()
|
2020-02-14 19:03:25 +00:00
|
|
|
sub := bs.attesterSlashingsFeed.Subscribe(ch)
|
|
|
|
defer sub.Unsubscribe()
|
2020-02-14 18:11:15 +00:00
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case slashing := <-ch:
|
2020-02-19 22:26:14 +00:00
|
|
|
if _, err := bs.beaconClient.SubmitAttesterSlashing(ctx, slashing); err != nil {
|
2020-02-14 18:11:15 +00:00
|
|
|
log.Error(err)
|
|
|
|
}
|
2020-02-14 19:03:25 +00:00
|
|
|
case <-sub.Err():
|
|
|
|
log.Error("Subscriber closed, exiting goroutine")
|
2020-02-14 18:11:15 +00:00
|
|
|
return
|
|
|
|
case <-ctx.Done():
|
2020-02-14 19:03:25 +00:00
|
|
|
log.Error("Context canceled")
|
2020-02-14 18:11:15 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|