prysm-pulse/slasher/detection/attestations/attestations.go

177 lines
5.9 KiB
Go
Raw Normal View History

package attestations
Surround detection (#3967) * min max span update logic * add comment to exported method * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * weak subjectivity error * add context * SlasherDb change to SlasherDB * gaz * raul feedback * fix old problem * gofmt goimports * gaz * import fix * change order * min max span detection * added benchmark * max diff without error * Update slasher/rpc/detect_update_min_max_span_bench_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/db/indexed_attestations.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_bench_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_bench_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * raul feedback, benchmark fix * raul feedback * gaz * fix merge * bench fix * another bench fix * comments * changed names of functions and proto * name change fix * name change fix * fix test * clarification comment * change to interface * Update proto/eth/v1alpha1/slasher.proto Co-Authored-By: Ivan Martinez <ivanthegreatdev@gmail.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * change order to reduce confusion * Update proto/eth/v1alpha1/slasher.proto Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Apply suggestions from code review Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go * Fix some comments * terence feedback * preston feedback * fix test * fix comments
2019-11-18 19:49:39 +00:00
import (
"context"
"fmt"
"github.com/pkg/errors"
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
slashpb "github.com/prysmaticlabs/prysm/proto/slashing"
Surround detection (#3967) * min max span update logic * add comment to exported method * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * weak subjectivity error * add context * SlasherDb change to SlasherDB * gaz * raul feedback * fix old problem * gofmt goimports * gaz * import fix * change order * min max span detection * added benchmark * max diff without error * Update slasher/rpc/detect_update_min_max_span_bench_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/db/indexed_attestations.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_bench_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_bench_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * raul feedback, benchmark fix * raul feedback * gaz * fix merge * bench fix * another bench fix * comments * changed names of functions and proto * name change fix * name change fix * fix test * clarification comment * change to interface * Update proto/eth/v1alpha1/slasher.proto Co-Authored-By: Ivan Martinez <ivanthegreatdev@gmail.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * change order to reduce confusion * Update proto/eth/v1alpha1/slasher.proto Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Apply suggestions from code review Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go * Fix some comments * terence feedback * preston feedback * fix test * fix comments
2019-11-18 19:49:39 +00:00
"github.com/prysmaticlabs/prysm/shared/params"
"go.opencensus.io/trace"
Surround detection (#3967) * min max span update logic * add comment to exported method * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * weak subjectivity error * add context * SlasherDb change to SlasherDB * gaz * raul feedback * fix old problem * gofmt goimports * gaz * import fix * change order * min max span detection * added benchmark * max diff without error * Update slasher/rpc/detect_update_min_max_span_bench_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/db/indexed_attestations.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_bench_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_bench_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * raul feedback, benchmark fix * raul feedback * gaz * fix merge * bench fix * another bench fix * comments * changed names of functions and proto * name change fix * name change fix * fix test * clarification comment * change to interface * Update proto/eth/v1alpha1/slasher.proto Co-Authored-By: Ivan Martinez <ivanthegreatdev@gmail.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * change order to reduce confusion * Update proto/eth/v1alpha1/slasher.proto Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Apply suggestions from code review Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go * Fix some comments * terence feedback * preston feedback * fix test * fix comments
2019-11-18 19:49:39 +00:00
)
// Detector is a function type used to implement the slashable surrounding/surrounded
// vote detection methods.
2020-02-20 14:56:37 +00:00
type detectFn = func(span *slashpb.MinMaxEpochSpan, sourceEpoch uint64, attDistance uint64) uint64
Surround detection (#3967) * min max span update logic * add comment to exported method * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * weak subjectivity error * add context * SlasherDb change to SlasherDB * gaz * raul feedback * fix old problem * gofmt goimports * gaz * import fix * change order * min max span detection * added benchmark * max diff without error * Update slasher/rpc/detect_update_min_max_span_bench_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/db/indexed_attestations.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_bench_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_bench_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * raul feedback, benchmark fix * raul feedback * gaz * fix merge * bench fix * another bench fix * comments * changed names of functions and proto * name change fix * name change fix * fix test * clarification comment * change to interface * Update proto/eth/v1alpha1/slasher.proto Co-Authored-By: Ivan Martinez <ivanthegreatdev@gmail.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * change order to reduce confusion * Update proto/eth/v1alpha1/slasher.proto Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Apply suggestions from code review Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go * Fix some comments * terence feedback * preston feedback * fix test * fix comments
2019-11-18 19:49:39 +00:00
// detectMax is a function for maxDetector used to detect surrounding attestations.
2020-02-20 14:56:37 +00:00
func detectMax(span *slashpb.MinMaxEpochSpan, attSourceEpoch uint64, attDistance uint64) uint64 {
maxSpan := uint64(span.MaxEpochSpan)
if maxSpan > attDistance {
return maxSpan + attSourceEpoch
Surround detection (#3967) * min max span update logic * add comment to exported method * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * weak subjectivity error * add context * SlasherDb change to SlasherDB * gaz * raul feedback * fix old problem * gofmt goimports * gaz * import fix * change order * min max span detection * added benchmark * max diff without error * Update slasher/rpc/detect_update_min_max_span_bench_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/db/indexed_attestations.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_bench_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_bench_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * raul feedback, benchmark fix * raul feedback * gaz * fix merge * bench fix * another bench fix * comments * changed names of functions and proto * name change fix * name change fix * fix test * clarification comment * change to interface * Update proto/eth/v1alpha1/slasher.proto Co-Authored-By: Ivan Martinez <ivanthegreatdev@gmail.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * change order to reduce confusion * Update proto/eth/v1alpha1/slasher.proto Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Apply suggestions from code review Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go * Fix some comments * terence feedback * preston feedback * fix test * fix comments
2019-11-18 19:49:39 +00:00
}
return 0
}
// detectMin is a function for minDetector used to detect surrounded attestations.
2020-02-20 14:56:37 +00:00
func detectMin(span *slashpb.MinMaxEpochSpan, attSourceEpoch uint64, attDistance uint64) uint64 {
minSpan := uint64(span.MinEpochSpan)
if minSpan > 0 && minSpan < attDistance {
return minSpan + attSourceEpoch
Surround detection (#3967) * min max span update logic * add comment to exported method * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * weak subjectivity error * add context * SlasherDb change to SlasherDB * gaz * raul feedback * fix old problem * gofmt goimports * gaz * import fix * change order * min max span detection * added benchmark * max diff without error * Update slasher/rpc/detect_update_min_max_span_bench_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/db/indexed_attestations.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_bench_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_bench_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * raul feedback, benchmark fix * raul feedback * gaz * fix merge * bench fix * another bench fix * comments * changed names of functions and proto * name change fix * name change fix * fix test * clarification comment * change to interface * Update proto/eth/v1alpha1/slasher.proto Co-Authored-By: Ivan Martinez <ivanthegreatdev@gmail.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * change order to reduce confusion * Update proto/eth/v1alpha1/slasher.proto Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Apply suggestions from code review Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go * Fix some comments * terence feedback * preston feedback * fix test * fix comments
2019-11-18 19:49:39 +00:00
}
return 0
}
// DetectAndUpdateSpans runs detection and updating for both min and max epoch spans, this is used for
// attestation slashing detection.
// Detailed here: https://github.com/protolambda/eth2-surround/blob/master/README.md#min-max-surround
func DetectAndUpdateSpans(
ctx context.Context,
spanMap *slashpb.EpochSpanMap,
2020-02-20 14:56:37 +00:00
att *ethpb.IndexedAttestation,
) (*slashpb.EpochSpanMap, uint64, error) {
ctx, span := trace.StartSpan(ctx, "Detection.DetectAndUpdateSpans")
defer span.End()
2020-02-20 14:56:37 +00:00
spanMap, minTargetEpoch, err := detectAndUpdateMinEpochSpan(ctx, spanMap, att.Data.Source.Epoch, att.Data.Target.Epoch)
if err != nil {
2020-02-20 14:56:37 +00:00
return nil, 0, errors.Wrap(err, "failed to update min spans")
}
2020-02-20 14:56:37 +00:00
spanMap, maxTargetEpoch, err := detectAndUpdateMaxEpochSpan(ctx, spanMap, att.Data.Source.Epoch, att.Data.Target.Epoch)
if err != nil {
2020-02-20 14:56:37 +00:00
return nil, 0, errors.Wrap(err, "failed to update max spans")
}
slashableEpoch := minTargetEpoch
if slashableEpoch == 0 {
slashableEpoch = maxTargetEpoch
}
2020-02-20 14:56:37 +00:00
return spanMap, slashableEpoch, nil
}
// detectAndUpdateMaxEpochSpan is used to detect and update the max span of an incoming attestation.
Surround detection (#3967) * min max span update logic * add comment to exported method * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * weak subjectivity error * add context * SlasherDb change to SlasherDB * gaz * raul feedback * fix old problem * gofmt goimports * gaz * import fix * change order * min max span detection * added benchmark * max diff without error * Update slasher/rpc/detect_update_min_max_span_bench_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/db/indexed_attestations.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_bench_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_bench_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * raul feedback, benchmark fix * raul feedback * gaz * fix merge * bench fix * another bench fix * comments * changed names of functions and proto * name change fix * name change fix * fix test * clarification comment * change to interface * Update proto/eth/v1alpha1/slasher.proto Co-Authored-By: Ivan Martinez <ivanthegreatdev@gmail.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * change order to reduce confusion * Update proto/eth/v1alpha1/slasher.proto Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Apply suggestions from code review Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go * Fix some comments * terence feedback * preston feedback * fix test * fix comments
2019-11-18 19:49:39 +00:00
// This is used for detecting surrounding votes.
// The max span is the span between the current attestation's source epoch and the furthest attestation's
// target epoch that has a lower (earlier) source epoch.
// Logic for this detection method was designed by https://github.com/protolambda
// Detailed here: https://github.com/protolambda/eth2-surround/blob/master/README.md#min-max-surround
func detectAndUpdateMaxEpochSpan(
ctx context.Context,
2020-02-20 14:56:37 +00:00
spanMap *slashpb.EpochSpanMap,
source uint64,
target uint64,
2020-02-20 14:56:37 +00:00
) (*slashpb.EpochSpanMap, uint64, error) {
ctx, span := trace.StartSpan(ctx, "Detection.detectAndUpdateMaxEpochSpan")
defer span.End()
2020-02-20 14:56:37 +00:00
if source > target {
return nil, 0, fmt.Errorf(
"source cannot be greater than target, received source %d, target %d",
source,
target,
)
Add surround check to endpoint (#4065) * first version of the watchtower api * service files * Begin work on grpc server * More changes to server * REnames and mock setup * working test * merge * double propose detection test * nishant review * todo change * gaz * fix service * gaz * remove unused import * gaz * resolve circular dependency * resolve circular dependency 2nd try * remove package * fix package * fix test * added tests * gaz * remove status check * gaz * remove context * remove context * change var name * moved to rpc dir * gaz * remove server code * gaz * slasher server * visibility change * pb * service update * gaz * slasher grpc server * making it work * setup db and start * gaz * service flags fixes * grpc service running * go imports * remove new initializer * gaz * remove feature flags * change back SetupSlasherDB * fix SetupSlasherDB calls * define err * fix bad merge * fix test * fix imports * fix imports * fix imports * add cancel * comment stop * fix cancel issue * remove unneeded code * bring back bad merge that removed TODO * remove use of epoch as am input * fixed slasher to be runable again * wait for channel close * gaz * small test * flags fix * fix flag order * double vote detection * remove source epoch from indexed attestation indices * change server method to receive indexed attestation * start implementation * double vote detection * proto * pb * fir comment * add surround detection and retrieval to endpoint * nishant review * import fix * fix miss order * fix detection 0 case added tests * terence review
2019-11-21 07:11:23 +00:00
}
2020-02-20 14:56:37 +00:00
spanMap, distance, targetEpoch, err := detectSlashingByEpochSpan(ctx, spanMap, source, target, detectMax)
Surround detection (#3967) * min max span update logic * add comment to exported method * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * weak subjectivity error * add context * SlasherDb change to SlasherDB * gaz * raul feedback * fix old problem * gofmt goimports * gaz * import fix * change order * min max span detection * added benchmark * max diff without error * Update slasher/rpc/detect_update_min_max_span_bench_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/db/indexed_attestations.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_bench_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_bench_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * raul feedback, benchmark fix * raul feedback * gaz * fix merge * bench fix * another bench fix * comments * changed names of functions and proto * name change fix * name change fix * fix test * clarification comment * change to interface * Update proto/eth/v1alpha1/slasher.proto Co-Authored-By: Ivan Martinez <ivanthegreatdev@gmail.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * change order to reduce confusion * Update proto/eth/v1alpha1/slasher.proto Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Apply suggestions from code review Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go * Fix some comments * terence feedback * preston feedback * fix test * fix comments
2019-11-18 19:49:39 +00:00
if err != nil {
2020-02-20 14:56:37 +00:00
return nil, 0, err
Surround detection (#3967) * min max span update logic * add comment to exported method * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * weak subjectivity error * add context * SlasherDb change to SlasherDB * gaz * raul feedback * fix old problem * gofmt goimports * gaz * import fix * change order * min max span detection * added benchmark * max diff without error * Update slasher/rpc/detect_update_min_max_span_bench_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/db/indexed_attestations.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_bench_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_bench_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * raul feedback, benchmark fix * raul feedback * gaz * fix merge * bench fix * another bench fix * comments * changed names of functions and proto * name change fix * name change fix * fix test * clarification comment * change to interface * Update proto/eth/v1alpha1/slasher.proto Co-Authored-By: Ivan Martinez <ivanthegreatdev@gmail.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * change order to reduce confusion * Update proto/eth/v1alpha1/slasher.proto Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Apply suggestions from code review Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go * Fix some comments * terence feedback * preston feedback * fix test * fix comments
2019-11-18 19:49:39 +00:00
}
if targetEpoch > 0 {
2020-02-20 14:56:37 +00:00
return spanMap, targetEpoch, nil
Surround detection (#3967) * min max span update logic * add comment to exported method * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * weak subjectivity error * add context * SlasherDb change to SlasherDB * gaz * raul feedback * fix old problem * gofmt goimports * gaz * import fix * change order * min max span detection * added benchmark * max diff without error * Update slasher/rpc/detect_update_min_max_span_bench_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/db/indexed_attestations.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_bench_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_bench_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * raul feedback, benchmark fix * raul feedback * gaz * fix merge * bench fix * another bench fix * comments * changed names of functions and proto * name change fix * name change fix * fix test * clarification comment * change to interface * Update proto/eth/v1alpha1/slasher.proto Co-Authored-By: Ivan Martinez <ivanthegreatdev@gmail.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * change order to reduce confusion * Update proto/eth/v1alpha1/slasher.proto Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Apply suggestions from code review Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go * Fix some comments * terence feedback * preston feedback * fix test * fix comments
2019-11-18 19:49:39 +00:00
}
Surround detection (#3967) * min max span update logic * add comment to exported method * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * weak subjectivity error * add context * SlasherDb change to SlasherDB * gaz * raul feedback * fix old problem * gofmt goimports * gaz * import fix * change order * min max span detection * added benchmark * max diff without error * Update slasher/rpc/detect_update_min_max_span_bench_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/db/indexed_attestations.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_bench_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_bench_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * raul feedback, benchmark fix * raul feedback * gaz * fix merge * bench fix * another bench fix * comments * changed names of functions and proto * name change fix * name change fix * fix test * clarification comment * change to interface * Update proto/eth/v1alpha1/slasher.proto Co-Authored-By: Ivan Martinez <ivanthegreatdev@gmail.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * change order to reduce confusion * Update proto/eth/v1alpha1/slasher.proto Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Apply suggestions from code review Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go * Fix some comments * terence feedback * preston feedback * fix test * fix comments
2019-11-18 19:49:39 +00:00
for i := uint64(1); i < target-source; i++ {
2020-02-20 14:56:37 +00:00
val := uint32(distance - i)
Surround detection (#3967) * min max span update logic * add comment to exported method * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * weak subjectivity error * add context * SlasherDb change to SlasherDB * gaz * raul feedback * fix old problem * gofmt goimports * gaz * import fix * change order * min max span detection * added benchmark * max diff without error * Update slasher/rpc/detect_update_min_max_span_bench_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/db/indexed_attestations.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_bench_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_bench_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * raul feedback, benchmark fix * raul feedback * gaz * fix merge * bench fix * another bench fix * comments * changed names of functions and proto * name change fix * name change fix * fix test * clarification comment * change to interface * Update proto/eth/v1alpha1/slasher.proto Co-Authored-By: Ivan Martinez <ivanthegreatdev@gmail.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * change order to reduce confusion * Update proto/eth/v1alpha1/slasher.proto Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Apply suggestions from code review Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go * Fix some comments * terence feedback * preston feedback * fix test * fix comments
2019-11-18 19:49:39 +00:00
if _, ok := spanMap.EpochSpanMap[source+i]; !ok {
spanMap.EpochSpanMap[source+i] = &slashpb.MinMaxEpochSpan{}
Surround detection (#3967) * min max span update logic * add comment to exported method * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * weak subjectivity error * add context * SlasherDb change to SlasherDB * gaz * raul feedback * fix old problem * gofmt goimports * gaz * import fix * change order * min max span detection * added benchmark * max diff without error * Update slasher/rpc/detect_update_min_max_span_bench_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/db/indexed_attestations.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_bench_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_bench_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * raul feedback, benchmark fix * raul feedback * gaz * fix merge * bench fix * another bench fix * comments * changed names of functions and proto * name change fix * name change fix * fix test * clarification comment * change to interface * Update proto/eth/v1alpha1/slasher.proto Co-Authored-By: Ivan Martinez <ivanthegreatdev@gmail.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * change order to reduce confusion * Update proto/eth/v1alpha1/slasher.proto Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Apply suggestions from code review Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go * Fix some comments * terence feedback * preston feedback * fix test * fix comments
2019-11-18 19:49:39 +00:00
}
if spanMap.EpochSpanMap[source+i].MaxEpochSpan < val {
spanMap.EpochSpanMap[source+i].MaxEpochSpan = val
} else {
break
}
}
2020-02-20 14:56:37 +00:00
return spanMap, 0, nil
Surround detection (#3967) * min max span update logic * add comment to exported method * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * weak subjectivity error * add context * SlasherDb change to SlasherDB * gaz * raul feedback * fix old problem * gofmt goimports * gaz * import fix * change order * min max span detection * added benchmark * max diff without error * Update slasher/rpc/detect_update_min_max_span_bench_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/db/indexed_attestations.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_bench_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_bench_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * raul feedback, benchmark fix * raul feedback * gaz * fix merge * bench fix * another bench fix * comments * changed names of functions and proto * name change fix * name change fix * fix test * clarification comment * change to interface * Update proto/eth/v1alpha1/slasher.proto Co-Authored-By: Ivan Martinez <ivanthegreatdev@gmail.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * change order to reduce confusion * Update proto/eth/v1alpha1/slasher.proto Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Apply suggestions from code review Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go * Fix some comments * terence feedback * preston feedback * fix test * fix comments
2019-11-18 19:49:39 +00:00
}
// detectAndUpdateMinEpochSpan is used to detect surrounded votes and update the min epoch span
Surround detection (#3967) * min max span update logic * add comment to exported method * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * weak subjectivity error * add context * SlasherDb change to SlasherDB * gaz * raul feedback * fix old problem * gofmt goimports * gaz * import fix * change order * min max span detection * added benchmark * max diff without error * Update slasher/rpc/detect_update_min_max_span_bench_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/db/indexed_attestations.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_bench_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_bench_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * raul feedback, benchmark fix * raul feedback * gaz * fix merge * bench fix * another bench fix * comments * changed names of functions and proto * name change fix * name change fix * fix test * clarification comment * change to interface * Update proto/eth/v1alpha1/slasher.proto Co-Authored-By: Ivan Martinez <ivanthegreatdev@gmail.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * change order to reduce confusion * Update proto/eth/v1alpha1/slasher.proto Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Apply suggestions from code review Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go * Fix some comments * terence feedback * preston feedback * fix test * fix comments
2019-11-18 19:49:39 +00:00
// of an incoming attestation.
// The min span is the span between the current attestations target epoch and the
// closest attestation's target distance.
//
// Logic is following the detection method designed by https://github.com/protolambda
// Detailed here: https://github.com/protolambda/eth2-surround/blob/master/README.md#min-max-surround
func detectAndUpdateMinEpochSpan(
ctx context.Context,
2020-02-20 14:56:37 +00:00
spanMap *slashpb.EpochSpanMap,
source uint64,
target uint64,
2020-02-20 14:56:37 +00:00
) (*slashpb.EpochSpanMap, uint64, error) {
ctx, span := trace.StartSpan(ctx, "Detection.detectAndUpdateMinEpochSpan")
defer span.End()
2020-02-20 14:56:37 +00:00
if source > target {
return nil, 0, fmt.Errorf(
"source cannot be greater than target, received source %d, target %d",
Add surround check to endpoint (#4065) * first version of the watchtower api * service files * Begin work on grpc server * More changes to server * REnames and mock setup * working test * merge * double propose detection test * nishant review * todo change * gaz * fix service * gaz * remove unused import * gaz * resolve circular dependency * resolve circular dependency 2nd try * remove package * fix package * fix test * added tests * gaz * remove status check * gaz * remove context * remove context * change var name * moved to rpc dir * gaz * remove server code * gaz * slasher server * visibility change * pb * service update * gaz * slasher grpc server * making it work * setup db and start * gaz * service flags fixes * grpc service running * go imports * remove new initializer * gaz * remove feature flags * change back SetupSlasherDB * fix SetupSlasherDB calls * define err * fix bad merge * fix test * fix imports * fix imports * fix imports * add cancel * comment stop * fix cancel issue * remove unneeded code * bring back bad merge that removed TODO * remove use of epoch as am input * fixed slasher to be runable again * wait for channel close * gaz * small test * flags fix * fix flag order * double vote detection * remove source epoch from indexed attestation indices * change server method to receive indexed attestation * start implementation * double vote detection * proto * pb * fir comment * add surround detection and retrieval to endpoint * nishant review * import fix * fix miss order * fix detection 0 case added tests * terence review
2019-11-21 07:11:23 +00:00
source,
2020-02-20 14:56:37 +00:00
target,
Add surround check to endpoint (#4065) * first version of the watchtower api * service files * Begin work on grpc server * More changes to server * REnames and mock setup * working test * merge * double propose detection test * nishant review * todo change * gaz * fix service * gaz * remove unused import * gaz * resolve circular dependency * resolve circular dependency 2nd try * remove package * fix package * fix test * added tests * gaz * remove status check * gaz * remove context * remove context * change var name * moved to rpc dir * gaz * remove server code * gaz * slasher server * visibility change * pb * service update * gaz * slasher grpc server * making it work * setup db and start * gaz * service flags fixes * grpc service running * go imports * remove new initializer * gaz * remove feature flags * change back SetupSlasherDB * fix SetupSlasherDB calls * define err * fix bad merge * fix test * fix imports * fix imports * fix imports * add cancel * comment stop * fix cancel issue * remove unneeded code * bring back bad merge that removed TODO * remove use of epoch as am input * fixed slasher to be runable again * wait for channel close * gaz * small test * flags fix * fix flag order * double vote detection * remove source epoch from indexed attestation indices * change server method to receive indexed attestation * start implementation * double vote detection * proto * pb * fir comment * add surround detection and retrieval to endpoint * nishant review * import fix * fix miss order * fix detection 0 case added tests * terence review
2019-11-21 07:11:23 +00:00
)
}
2020-02-20 14:56:37 +00:00
spanMap, _, targetEpoch, err := detectSlashingByEpochSpan(ctx, spanMap, source, target, detectMin)
Surround detection (#3967) * min max span update logic * add comment to exported method * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * weak subjectivity error * add context * SlasherDb change to SlasherDB * gaz * raul feedback * fix old problem * gofmt goimports * gaz * import fix * change order * min max span detection * added benchmark * max diff without error * Update slasher/rpc/detect_update_min_max_span_bench_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/db/indexed_attestations.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_bench_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_bench_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * raul feedback, benchmark fix * raul feedback * gaz * fix merge * bench fix * another bench fix * comments * changed names of functions and proto * name change fix * name change fix * fix test * clarification comment * change to interface * Update proto/eth/v1alpha1/slasher.proto Co-Authored-By: Ivan Martinez <ivanthegreatdev@gmail.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * change order to reduce confusion * Update proto/eth/v1alpha1/slasher.proto Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Apply suggestions from code review Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go * Fix some comments * terence feedback * preston feedback * fix test * fix comments
2019-11-18 19:49:39 +00:00
if err != nil {
2020-02-20 14:56:37 +00:00
return nil, 0, err
Surround detection (#3967) * min max span update logic * add comment to exported method * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * weak subjectivity error * add context * SlasherDb change to SlasherDB * gaz * raul feedback * fix old problem * gofmt goimports * gaz * import fix * change order * min max span detection * added benchmark * max diff without error * Update slasher/rpc/detect_update_min_max_span_bench_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/db/indexed_attestations.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_bench_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_bench_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * raul feedback, benchmark fix * raul feedback * gaz * fix merge * bench fix * another bench fix * comments * changed names of functions and proto * name change fix * name change fix * fix test * clarification comment * change to interface * Update proto/eth/v1alpha1/slasher.proto Co-Authored-By: Ivan Martinez <ivanthegreatdev@gmail.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * change order to reduce confusion * Update proto/eth/v1alpha1/slasher.proto Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Apply suggestions from code review Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go * Fix some comments * terence feedback * preston feedback * fix test * fix comments
2019-11-18 19:49:39 +00:00
}
if targetEpoch > 0 {
2020-02-20 14:56:37 +00:00
return spanMap, targetEpoch, nil
Surround detection (#3967) * min max span update logic * add comment to exported method * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * weak subjectivity error * add context * SlasherDb change to SlasherDB * gaz * raul feedback * fix old problem * gofmt goimports * gaz * import fix * change order * min max span detection * added benchmark * max diff without error * Update slasher/rpc/detect_update_min_max_span_bench_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/db/indexed_attestations.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_bench_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_bench_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * raul feedback, benchmark fix * raul feedback * gaz * fix merge * bench fix * another bench fix * comments * changed names of functions and proto * name change fix * name change fix * fix test * clarification comment * change to interface * Update proto/eth/v1alpha1/slasher.proto Co-Authored-By: Ivan Martinez <ivanthegreatdev@gmail.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * change order to reduce confusion * Update proto/eth/v1alpha1/slasher.proto Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Apply suggestions from code review Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go * Fix some comments * terence feedback * preston feedback * fix test * fix comments
2019-11-18 19:49:39 +00:00
}
if source == 0 {
2020-02-20 14:56:37 +00:00
return spanMap, 0, nil
Surround detection (#3967) * min max span update logic * add comment to exported method * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * weak subjectivity error * add context * SlasherDb change to SlasherDB * gaz * raul feedback * fix old problem * gofmt goimports * gaz * import fix * change order * min max span detection * added benchmark * max diff without error * Update slasher/rpc/detect_update_min_max_span_bench_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/db/indexed_attestations.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_bench_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_bench_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * raul feedback, benchmark fix * raul feedback * gaz * fix merge * bench fix * another bench fix * comments * changed names of functions and proto * name change fix * name change fix * fix test * clarification comment * change to interface * Update proto/eth/v1alpha1/slasher.proto Co-Authored-By: Ivan Martinez <ivanthegreatdev@gmail.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * change order to reduce confusion * Update proto/eth/v1alpha1/slasher.proto Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Apply suggestions from code review Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go * Fix some comments * terence feedback * preston feedback * fix test * fix comments
2019-11-18 19:49:39 +00:00
}
Surround detection (#3967) * min max span update logic * add comment to exported method * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * weak subjectivity error * add context * SlasherDb change to SlasherDB * gaz * raul feedback * fix old problem * gofmt goimports * gaz * import fix * change order * min max span detection * added benchmark * max diff without error * Update slasher/rpc/detect_update_min_max_span_bench_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/db/indexed_attestations.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_bench_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_bench_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * raul feedback, benchmark fix * raul feedback * gaz * fix merge * bench fix * another bench fix * comments * changed names of functions and proto * name change fix * name change fix * fix test * clarification comment * change to interface * Update proto/eth/v1alpha1/slasher.proto Co-Authored-By: Ivan Martinez <ivanthegreatdev@gmail.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * change order to reduce confusion * Update proto/eth/v1alpha1/slasher.proto Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Apply suggestions from code review Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go * Fix some comments * terence feedback * preston feedback * fix test * fix comments
2019-11-18 19:49:39 +00:00
for i := source - 1; i > 0; i-- {
val := uint32(target - (i))
if _, ok := spanMap.EpochSpanMap[i]; !ok {
spanMap.EpochSpanMap[i] = &slashpb.MinMaxEpochSpan{}
Surround detection (#3967) * min max span update logic * add comment to exported method * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * weak subjectivity error * add context * SlasherDb change to SlasherDB * gaz * raul feedback * fix old problem * gofmt goimports * gaz * import fix * change order * min max span detection * added benchmark * max diff without error * Update slasher/rpc/detect_update_min_max_span_bench_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/db/indexed_attestations.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_bench_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_bench_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * raul feedback, benchmark fix * raul feedback * gaz * fix merge * bench fix * another bench fix * comments * changed names of functions and proto * name change fix * name change fix * fix test * clarification comment * change to interface * Update proto/eth/v1alpha1/slasher.proto Co-Authored-By: Ivan Martinez <ivanthegreatdev@gmail.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * change order to reduce confusion * Update proto/eth/v1alpha1/slasher.proto Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Apply suggestions from code review Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go * Fix some comments * terence feedback * preston feedback * fix test * fix comments
2019-11-18 19:49:39 +00:00
}
if spanMap.EpochSpanMap[i].MinEpochSpan == 0 || spanMap.EpochSpanMap[i].MinEpochSpan > val {
spanMap.EpochSpanMap[i].MinEpochSpan = val
} else {
break
}
}
2020-02-20 14:56:37 +00:00
return spanMap, 0, nil
Surround detection (#3967) * min max span update logic * add comment to exported method * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * weak subjectivity error * add context * SlasherDb change to SlasherDB * gaz * raul feedback * fix old problem * gofmt goimports * gaz * import fix * change order * min max span detection * added benchmark * max diff without error * Update slasher/rpc/detect_update_min_max_span_bench_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/db/indexed_attestations.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_bench_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_bench_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * raul feedback, benchmark fix * raul feedback * gaz * fix merge * bench fix * another bench fix * comments * changed names of functions and proto * name change fix * name change fix * fix test * clarification comment * change to interface * Update proto/eth/v1alpha1/slasher.proto Co-Authored-By: Ivan Martinez <ivanthegreatdev@gmail.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * change order to reduce confusion * Update proto/eth/v1alpha1/slasher.proto Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Apply suggestions from code review Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go * Fix some comments * terence feedback * preston feedback * fix test * fix comments
2019-11-18 19:49:39 +00:00
}
// detectSlashingByEpochSpan is used to detect if a slashable event is present
// in the db by checking either the closest attestation target or the furthest
// attestation target. This method receives a detector function in order to be used
// for both surrounding and surrounded vote cases.
func detectSlashingByEpochSpan(
ctx context.Context,
2020-02-20 14:56:37 +00:00
spanMap *slashpb.EpochSpanMap,
source uint64,
target uint64,
detector detectFn,
2020-02-20 14:56:37 +00:00
) (*slashpb.EpochSpanMap, uint64, uint64, error) {
ctx, span := trace.StartSpan(ctx, "Detection.detectSlashingByEpochSpan")
defer span.End()
2020-02-20 14:56:37 +00:00
distance := target - source
if distance > params.BeaconConfig().WeakSubjectivityPeriod {
return nil, distance, 0, fmt.Errorf(
"attestation span was greater than waek subjectivity period, received: %d",
distance,
Surround detection (#3967) * min max span update logic * add comment to exported method * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * weak subjectivity error * add context * SlasherDb change to SlasherDB * gaz * raul feedback * fix old problem * gofmt goimports * gaz * import fix * change order * min max span detection * added benchmark * max diff without error * Update slasher/rpc/detect_update_min_max_span_bench_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/db/indexed_attestations.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_bench_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_bench_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * raul feedback, benchmark fix * raul feedback * gaz * fix merge * bench fix * another bench fix * comments * changed names of functions and proto * name change fix * name change fix * fix test * clarification comment * change to interface * Update proto/eth/v1alpha1/slasher.proto Co-Authored-By: Ivan Martinez <ivanthegreatdev@gmail.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * change order to reduce confusion * Update proto/eth/v1alpha1/slasher.proto Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Apply suggestions from code review Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go * Fix some comments * terence feedback * preston feedback * fix test * fix comments
2019-11-18 19:49:39 +00:00
)
}
if _, ok := spanMap.EpochSpanMap[source]; ok {
2020-02-20 14:56:37 +00:00
return spanMap, distance, detector(spanMap.EpochSpanMap[source], source, distance), nil
Surround detection (#3967) * min max span update logic * add comment to exported method * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * weak subjectivity error * add context * SlasherDb change to SlasherDB * gaz * raul feedback * fix old problem * gofmt goimports * gaz * import fix * change order * min max span detection * added benchmark * max diff without error * Update slasher/rpc/detect_update_min_max_span_bench_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/db/indexed_attestations.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_bench_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_bench_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * raul feedback, benchmark fix * raul feedback * gaz * fix merge * bench fix * another bench fix * comments * changed names of functions and proto * name change fix * name change fix * fix test * clarification comment * change to interface * Update proto/eth/v1alpha1/slasher.proto Co-Authored-By: Ivan Martinez <ivanthegreatdev@gmail.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * change order to reduce confusion * Update proto/eth/v1alpha1/slasher.proto Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Apply suggestions from code review Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go * Fix some comments * terence feedback * preston feedback * fix test * fix comments
2019-11-18 19:49:39 +00:00
}
2020-02-20 14:56:37 +00:00
return spanMap, distance, 0, nil
Surround detection (#3967) * min max span update logic * add comment to exported method * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * weak subjectivity error * add context * SlasherDb change to SlasherDB * gaz * raul feedback * fix old problem * gofmt goimports * gaz * import fix * change order * min max span detection * added benchmark * max diff without error * Update slasher/rpc/detect_update_min_max_span_bench_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/db/indexed_attestations.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_bench_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span_bench_test.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * raul feedback, benchmark fix * raul feedback * gaz * fix merge * bench fix * another bench fix * comments * changed names of functions and proto * name change fix * name change fix * fix test * clarification comment * change to interface * Update proto/eth/v1alpha1/slasher.proto Co-Authored-By: Ivan Martinez <ivanthegreatdev@gmail.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com> * change order to reduce confusion * Update proto/eth/v1alpha1/slasher.proto Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Apply suggestions from code review Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/rpc/detect_update_min_max_span.go * Fix some comments * terence feedback * preston feedback * fix test * fix comments
2019-11-18 19:49:39 +00:00
}