2020-02-13 09:19:46 -07:00
|
|
|
package kv
|
2019-09-02 18:36:29 +03:00
|
|
|
|
|
|
|
import (
|
2021-02-23 02:20:57 +03:00
|
|
|
types "github.com/prysmaticlabs/eth2-types"
|
2019-09-02 18:36:29 +03:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/bytesutil"
|
2021-02-09 13:05:22 +03:00
|
|
|
dbtypes "github.com/prysmaticlabs/prysm/slasher/db/types"
|
2019-09-02 18:36:29 +03:00
|
|
|
)
|
|
|
|
|
2020-02-19 16:26:14 -06:00
|
|
|
const (
|
2020-05-31 15:47:15 -07:00
|
|
|
latestEpochKey = "LATEST_EPOCH_DETECTED"
|
|
|
|
chainHeadKey = "CHAIN_HEAD"
|
2020-02-19 16:26:14 -06:00
|
|
|
)
|
2020-01-29 07:14:51 +05:30
|
|
|
|
2019-09-02 18:36:29 +03:00
|
|
|
var (
|
2020-02-27 11:22:39 -06:00
|
|
|
indexedAttestationsRootsByTargetBucket = []byte("indexed-attestations-roots-by-target")
|
|
|
|
indexedAttestationsBucket = []byte("indexed-attestations")
|
2020-02-19 16:26:14 -06:00
|
|
|
// Slasher-related buckets.
|
2019-10-19 09:05:09 +05:30
|
|
|
historicIndexedAttestationsBucket = []byte("historic-indexed-attestations-bucket")
|
|
|
|
historicBlockHeadersBucket = []byte("historic-block-headers-bucket")
|
2020-10-26 14:15:42 +02:00
|
|
|
highestAttestationBucket = []byte("highest-attestation-bucket")
|
2020-01-14 07:43:25 +05:30
|
|
|
slashingBucket = []byte("slashing-bucket")
|
2020-02-19 16:26:14 -06:00
|
|
|
chainDataBucket = []byte("chain-data-bucket")
|
2020-02-10 00:57:20 -05:00
|
|
|
compressedIdxAttsBucket = []byte("compressed-idx-atts-bucket")
|
2019-11-05 19:24:27 +05:30
|
|
|
validatorsPublicKeysBucket = []byte("validators-public-keys-bucket")
|
2019-12-10 14:45:14 -05:00
|
|
|
// In order to quickly detect surround and surrounded attestations we need to store
|
2019-11-07 01:38:20 +05:30
|
|
|
// 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
|
2020-06-02 17:41:21 +03:00
|
|
|
validatorsMinMaxSpanBucket = []byte("validators-min-max-span-bucket")
|
|
|
|
validatorsMinMaxSpanBucketNew = []byte("validators-min-max-span-bucket-new")
|
2019-09-02 18:36:29 +03:00
|
|
|
)
|
|
|
|
|
2021-02-22 17:40:58 -08:00
|
|
|
func encodeSlotValidatorIndex(slot types.Slot, validatorIndex types.ValidatorIndex) []byte {
|
|
|
|
return append(bytesutil.Bytes8(uint64(slot)), bytesutil.Bytes8(uint64(validatorIndex))...)
|
2019-09-02 18:36:29 +03:00
|
|
|
}
|
|
|
|
|
2021-02-22 17:40:58 -08:00
|
|
|
func encodeSlotValidatorIndexSig(slot types.Slot, validatorIndex types.ValidatorIndex, sig []byte) []byte {
|
|
|
|
return append(append(bytesutil.Bytes8(uint64(slot)), bytesutil.Bytes8(uint64(validatorIndex))...), sig...)
|
2019-09-02 18:36:29 +03:00
|
|
|
}
|
2019-10-19 09:05:09 +05:30
|
|
|
|
2021-02-09 13:05:22 +03:00
|
|
|
func encodeEpochSig(targetEpoch types.Epoch, sig []byte) []byte {
|
|
|
|
return append(bytesutil.Bytes8(uint64(targetEpoch)), sig...)
|
2019-10-19 09:05:09 +05:30
|
|
|
}
|
2021-02-09 13:05:22 +03:00
|
|
|
func encodeType(st dbtypes.SlashingType) []byte {
|
2020-01-14 07:43:25 +05:30
|
|
|
return []byte{byte(st)}
|
|
|
|
}
|
2021-02-09 13:05:22 +03:00
|
|
|
func encodeTypeRoot(st dbtypes.SlashingType, root [32]byte) []byte {
|
2020-01-14 07:43:25 +05:30
|
|
|
return append([]byte{byte(st)}, root[:]...)
|
|
|
|
}
|