prysm-pulse/slasher/db/kv/schema.go
Alon Muroch a04b7c2e4f
Slasher highest source target (#7604)
* WIP - slasher highest attestation start

* fixed previous

* highest source and target

* highest attestation cache

* cleanup

* persist + fixes

* PR fixes and cleanup

* slashing proto

* highest att. api

* cleanup + tests

* increased highest att. cache to 300K

* removed highest att. api (for a separate PR)

* fixed linting

* bazel build fix

* highest att. kv test

* slasher highest att. test + purge + fix on eviction persist performance

* cleanup + linting

* linting + test fixes

* bazel gazelle run

* PR fixes

* run goimports

* go mod tidy

* ineffectual assignment fix

* run gazelle

* bazel gazelle run

* test fixes

* linter fix

* Apply suggestions from code review

Co-authored-by: Shay Zluf <thezluf@gmail.com>

* goimports run

* cache tests

* A bunch of small fixes

* gazelle fix + gofmt

* merge fixes

* kv ordering fix

* small typos and text fixes

* capital letter fix

Co-authored-by: Shay Zluf <thezluf@gmail.com>
2020-10-26 14:15:42 +02:00

48 lines
1.9 KiB
Go

package kv
import (
"github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/slasher/db/types"
)
const (
latestEpochKey = "LATEST_EPOCH_DETECTED"
chainHeadKey = "CHAIN_HEAD"
)
var (
indexedAttestationsRootsByTargetBucket = []byte("indexed-attestations-roots-by-target")
indexedAttestationsBucket = []byte("indexed-attestations")
// Slasher-related buckets.
historicIndexedAttestationsBucket = []byte("historic-indexed-attestations-bucket")
historicBlockHeadersBucket = []byte("historic-block-headers-bucket")
highestAttestationBucket = []byte("highest-attestation-bucket")
slashingBucket = []byte("slashing-bucket")
chainDataBucket = []byte("chain-data-bucket")
compressedIdxAttsBucket = []byte("compressed-idx-atts-bucket")
validatorsPublicKeysBucket = []byte("validators-public-keys-bucket")
// In order to quickly detect surround and surrounded attestations we need to store
// the min and max span for each validator for each epoch.
// see https://github.com/protolambda/eth2-surround/blob/master/README.md#min-max-surround
validatorsMinMaxSpanBucket = []byte("validators-min-max-span-bucket")
validatorsMinMaxSpanBucketNew = []byte("validators-min-max-span-bucket-new")
)
func encodeSlotValidatorID(slot, validatorID uint64) []byte {
return append(bytesutil.Bytes8(slot), bytesutil.Bytes8(validatorID)...)
}
func encodeSlotValidatorIDSig(slot, validatorID uint64, sig []byte) []byte {
return append(append(bytesutil.Bytes8(slot), bytesutil.Bytes8(validatorID)...), sig...)
}
func encodeEpochSig(targetEpoch uint64, sig []byte) []byte {
return append(bytesutil.Bytes8(targetEpoch), sig...)
}
func encodeType(st types.SlashingType) []byte {
return []byte{byte(st)}
}
func encodeTypeRoot(st types.SlashingType, root [32]byte) []byte {
return append([]byte{byte(st)}, root[:]...)
}