From 18fbdd53b9eaaab46626598a398576d0e0a73b4a Mon Sep 17 00:00:00 2001 From: Ivan Martinez Date: Mon, 10 Feb 2020 00:57:20 -0500 Subject: [PATCH] Slasher proto and function renames (#4797) * Rename elements for clarity * Merge branch 'master' of https://github.com/prysmaticlabs/Prysm into slasher-renames * Fix test * Rename more functions * Cleanup * Fix logs * Merge branch 'master' of https://github.com/prysmaticlabs/Prysm into slasher-renames * Reorganize and clean up logs * Address comments * Add comments --- proto/slashing/slashing.pb.go | 284 +++++++++++++---------------- proto/slashing/slashing.proto | 12 +- slasher/db/block_header.go | 4 +- slasher/db/block_header_test.go | 12 +- slasher/db/db.go | 16 +- slasher/db/indexed_attestations.go | 52 +++--- slasher/db/schema.go | 2 +- slasher/rpc/server.go | 2 +- slasher/service/BUILD.bazel | 1 + slasher/service/data_update.go | 210 ++++++++++----------- slasher/service/service.go | 103 ++++++----- validator/db/db.go | 2 +- 12 files changed, 344 insertions(+), 356 deletions(-) diff --git a/proto/slashing/slashing.pb.go b/proto/slashing/slashing.pb.go index 41de3439ddee..589c750b5ddd 100755 --- a/proto/slashing/slashing.pb.go +++ b/proto/slashing/slashing.pb.go @@ -61,7 +61,7 @@ func (SlashingStatusRequest_SlashingStatus) EnumDescriptor() ([]byte, []int) { return fileDescriptor_da7e95107d0081b4, []int{9, 0} } -type ValidatorIDToIdxAtt struct { +type CompressedIdxAtt struct { Indices []uint64 `protobuf:"varint,1,rep,packed,name=indices,proto3" json:"indices,omitempty"` DataRoot []byte `protobuf:"bytes,2,opt,name=data_root,json=dataRoot,proto3" json:"data_root,omitempty"` Signature []byte `protobuf:"bytes,3,opt,name=signature,proto3" json:"signature,omitempty"` @@ -70,18 +70,18 @@ type ValidatorIDToIdxAtt struct { XXX_sizecache int32 `json:"-"` } -func (m *ValidatorIDToIdxAtt) Reset() { *m = ValidatorIDToIdxAtt{} } -func (m *ValidatorIDToIdxAtt) String() string { return proto.CompactTextString(m) } -func (*ValidatorIDToIdxAtt) ProtoMessage() {} -func (*ValidatorIDToIdxAtt) Descriptor() ([]byte, []int) { +func (m *CompressedIdxAtt) Reset() { *m = CompressedIdxAtt{} } +func (m *CompressedIdxAtt) String() string { return proto.CompactTextString(m) } +func (*CompressedIdxAtt) ProtoMessage() {} +func (*CompressedIdxAtt) Descriptor() ([]byte, []int) { return fileDescriptor_da7e95107d0081b4, []int{0} } -func (m *ValidatorIDToIdxAtt) XXX_Unmarshal(b []byte) error { +func (m *CompressedIdxAtt) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *ValidatorIDToIdxAtt) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *CompressedIdxAtt) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_ValidatorIDToIdxAtt.Marshal(b, m, deterministic) + return xxx_messageInfo_CompressedIdxAtt.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -91,58 +91,58 @@ func (m *ValidatorIDToIdxAtt) XXX_Marshal(b []byte, deterministic bool) ([]byte, return b[:n], nil } } -func (m *ValidatorIDToIdxAtt) XXX_Merge(src proto.Message) { - xxx_messageInfo_ValidatorIDToIdxAtt.Merge(m, src) +func (m *CompressedIdxAtt) XXX_Merge(src proto.Message) { + xxx_messageInfo_CompressedIdxAtt.Merge(m, src) } -func (m *ValidatorIDToIdxAtt) XXX_Size() int { +func (m *CompressedIdxAtt) XXX_Size() int { return m.Size() } -func (m *ValidatorIDToIdxAtt) XXX_DiscardUnknown() { - xxx_messageInfo_ValidatorIDToIdxAtt.DiscardUnknown(m) +func (m *CompressedIdxAtt) XXX_DiscardUnknown() { + xxx_messageInfo_CompressedIdxAtt.DiscardUnknown(m) } -var xxx_messageInfo_ValidatorIDToIdxAtt proto.InternalMessageInfo +var xxx_messageInfo_CompressedIdxAtt proto.InternalMessageInfo -func (m *ValidatorIDToIdxAtt) GetIndices() []uint64 { +func (m *CompressedIdxAtt) GetIndices() []uint64 { if m != nil { return m.Indices } return nil } -func (m *ValidatorIDToIdxAtt) GetDataRoot() []byte { +func (m *CompressedIdxAtt) GetDataRoot() []byte { if m != nil { return m.DataRoot } return nil } -func (m *ValidatorIDToIdxAtt) GetSignature() []byte { +func (m *CompressedIdxAtt) GetSignature() []byte { if m != nil { return m.Signature } return nil } -type ValidatorIDToIdxAttList struct { - IndicesList []*ValidatorIDToIdxAtt `protobuf:"bytes,1,rep,name=indicesList,proto3" json:"indicesList,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` +type CompressedIdxAttList struct { + List []*CompressedIdxAtt `protobuf:"bytes,1,rep,name=list,proto3" json:"list,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` } -func (m *ValidatorIDToIdxAttList) Reset() { *m = ValidatorIDToIdxAttList{} } -func (m *ValidatorIDToIdxAttList) String() string { return proto.CompactTextString(m) } -func (*ValidatorIDToIdxAttList) ProtoMessage() {} -func (*ValidatorIDToIdxAttList) Descriptor() ([]byte, []int) { +func (m *CompressedIdxAttList) Reset() { *m = CompressedIdxAttList{} } +func (m *CompressedIdxAttList) String() string { return proto.CompactTextString(m) } +func (*CompressedIdxAttList) ProtoMessage() {} +func (*CompressedIdxAttList) Descriptor() ([]byte, []int) { return fileDescriptor_da7e95107d0081b4, []int{1} } -func (m *ValidatorIDToIdxAttList) XXX_Unmarshal(b []byte) error { +func (m *CompressedIdxAttList) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *ValidatorIDToIdxAttList) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *CompressedIdxAttList) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_ValidatorIDToIdxAttList.Marshal(b, m, deterministic) + return xxx_messageInfo_CompressedIdxAttList.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -152,21 +152,21 @@ func (m *ValidatorIDToIdxAttList) XXX_Marshal(b []byte, deterministic bool) ([]b return b[:n], nil } } -func (m *ValidatorIDToIdxAttList) XXX_Merge(src proto.Message) { - xxx_messageInfo_ValidatorIDToIdxAttList.Merge(m, src) +func (m *CompressedIdxAttList) XXX_Merge(src proto.Message) { + xxx_messageInfo_CompressedIdxAttList.Merge(m, src) } -func (m *ValidatorIDToIdxAttList) XXX_Size() int { +func (m *CompressedIdxAttList) XXX_Size() int { return m.Size() } -func (m *ValidatorIDToIdxAttList) XXX_DiscardUnknown() { - xxx_messageInfo_ValidatorIDToIdxAttList.DiscardUnknown(m) +func (m *CompressedIdxAttList) XXX_DiscardUnknown() { + xxx_messageInfo_CompressedIdxAttList.DiscardUnknown(m) } -var xxx_messageInfo_ValidatorIDToIdxAttList proto.InternalMessageInfo +var xxx_messageInfo_CompressedIdxAttList proto.InternalMessageInfo -func (m *ValidatorIDToIdxAttList) GetIndicesList() []*ValidatorIDToIdxAtt { +func (m *CompressedIdxAttList) GetList() []*CompressedIdxAtt { if m != nil { - return m.IndicesList + return m.List } return nil } @@ -581,8 +581,8 @@ func (m *SlashingStatusRequest) GetStatus() SlashingStatusRequest_SlashingStatus func init() { proto.RegisterEnum("ethereum.slashing.SlashingStatusRequest_SlashingStatus", SlashingStatusRequest_SlashingStatus_name, SlashingStatusRequest_SlashingStatus_value) - proto.RegisterType((*ValidatorIDToIdxAtt)(nil), "ethereum.slashing.ValidatorIDToIdxAtt") - proto.RegisterType((*ValidatorIDToIdxAttList)(nil), "ethereum.slashing.ValidatorIDToIdxAttList") + proto.RegisterType((*CompressedIdxAtt)(nil), "ethereum.slashing.CompressedIdxAtt") + proto.RegisterType((*CompressedIdxAttList)(nil), "ethereum.slashing.CompressedIdxAttList") proto.RegisterType((*ProposerSlashingRequest)(nil), "ethereum.slashing.ProposerSlashingRequest") proto.RegisterType((*ProposerSlashingResponse)(nil), "ethereum.slashing.ProposerSlashingResponse") proto.RegisterType((*AttesterSlashingResponse)(nil), "ethereum.slashing.AttesterSlashingResponse") @@ -598,59 +598,59 @@ func init() { func init() { proto.RegisterFile("proto/slashing/slashing.proto", fileDescriptor_da7e95107d0081b4) } var fileDescriptor_da7e95107d0081b4 = []byte{ - // 827 bytes of a gzipped FileDescriptorProto + // 825 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x55, 0xdd, 0x6e, 0xe3, 0x54, - 0x10, 0xc6, 0x4d, 0x69, 0xb7, 0x93, 0x90, 0xba, 0x67, 0x17, 0x36, 0x0a, 0xd0, 0xad, 0x2c, 0xc4, - 0x96, 0x9f, 0x75, 0xb6, 0xe1, 0x82, 0x85, 0xbb, 0x46, 0x54, 0x6a, 0x24, 0xaa, 0x05, 0xa7, 0xb0, - 0x57, 0xc8, 0x3a, 0xb6, 0x67, 0x93, 0xb3, 0x75, 0xce, 0x31, 0x3e, 0xe3, 0x6c, 0xfb, 0x1e, 0xf0, - 0x1c, 0xbc, 0x02, 0x97, 0x5c, 0x70, 0xc1, 0x13, 0x20, 0xd4, 0x07, 0xe0, 0x01, 0xb8, 0x42, 0x3e, - 0x76, 0x5a, 0x27, 0x71, 0xa4, 0x5d, 0xed, 0x9d, 0xe7, 0x9b, 0x9f, 0x6f, 0xe6, 0x9b, 0x93, 0x09, - 0x7c, 0x98, 0xa4, 0x8a, 0x54, 0x4f, 0xc7, 0x5c, 0x4f, 0x84, 0x1c, 0xdf, 0x7c, 0xb8, 0x06, 0x67, - 0x7b, 0x48, 0x13, 0x4c, 0x31, 0x9b, 0xba, 0x73, 0x47, 0xf7, 0x01, 0xd2, 0xa4, 0x37, 0x3b, 0xe2, - 0x71, 0x32, 0xe1, 0x47, 0xbd, 0x00, 0x79, 0xa8, 0xa4, 0x1f, 0xc4, 0x2a, 0xbc, 0x28, 0x72, 0xba, - 0x8f, 0xc6, 0x82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 0x89, 0x38, 0xee, 0xfe, 0x7e, 0xbd, 0x67, 0xfd, 0x79, 0xbd, + 0x67, 0xfd, 0x7d, 0xbd, 0x67, 0x05, 0xf7, 0xcc, 0x5f, 0xf7, 0x8b, 0xff, 0x02, 0x00, 0x00, 0xff, + 0xff, 0x43, 0xb9, 0xf2, 0x52, 0xf9, 0x07, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -841,7 +841,7 @@ var _Slasher_serviceDesc = grpc.ServiceDesc{ Metadata: "proto/slashing/slashing.proto", } -func (m *ValidatorIDToIdxAtt) Marshal() (dAtA []byte, err error) { +func (m *CompressedIdxAtt) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -851,12 +851,12 @@ func (m *ValidatorIDToIdxAtt) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *ValidatorIDToIdxAtt) MarshalTo(dAtA []byte) (int, error) { +func (m *CompressedIdxAtt) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *ValidatorIDToIdxAtt) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *CompressedIdxAtt) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -900,7 +900,7 @@ func (m *ValidatorIDToIdxAtt) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } -func (m *ValidatorIDToIdxAttList) Marshal() (dAtA []byte, err error) { +func (m *CompressedIdxAttList) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -910,12 +910,12 @@ func (m *ValidatorIDToIdxAttList) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *ValidatorIDToIdxAttList) MarshalTo(dAtA []byte) (int, error) { +func (m *CompressedIdxAttList) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *ValidatorIDToIdxAttList) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *CompressedIdxAttList) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -924,10 +924,10 @@ func (m *ValidatorIDToIdxAttList) MarshalToSizedBuffer(dAtA []byte) (int, error) i -= len(m.XXX_unrecognized) copy(dAtA[i:], m.XXX_unrecognized) } - if len(m.IndicesList) > 0 { - for iNdEx := len(m.IndicesList) - 1; iNdEx >= 0; iNdEx-- { + if len(m.List) > 0 { + for iNdEx := len(m.List) - 1; iNdEx >= 0; iNdEx-- { { - size, err := m.IndicesList[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + size, err := m.List[iNdEx].MarshalToSizedBuffer(dAtA[:i]) if err != nil { return 0, err } @@ -1284,7 +1284,7 @@ func encodeVarintSlashing(dAtA []byte, offset int, v uint64) int { dAtA[offset] = uint8(v) return base } -func (m *ValidatorIDToIdxAtt) Size() (n int) { +func (m *CompressedIdxAtt) Size() (n int) { if m == nil { return 0 } @@ -1311,14 +1311,14 @@ func (m *ValidatorIDToIdxAtt) Size() (n int) { return n } -func (m *ValidatorIDToIdxAttList) Size() (n int) { +func (m *CompressedIdxAttList) Size() (n int) { if m == nil { return 0 } var l int _ = l - if len(m.IndicesList) > 0 { - for _, e := range m.IndicesList { + if len(m.List) > 0 { + for _, e := range m.List { l = e.Size() n += 1 + l + sovSlashing(uint64(l)) } @@ -1490,7 +1490,7 @@ func sovSlashing(x uint64) (n int) { func sozSlashing(x uint64) (n int) { return sovSlashing(uint64((x << 1) ^ uint64((int64(x) >> 63)))) } -func (m *ValidatorIDToIdxAtt) Unmarshal(dAtA []byte) error { +func (m *CompressedIdxAtt) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -1513,10 +1513,10 @@ func (m *ValidatorIDToIdxAtt) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: ValidatorIDToIdxAtt: wiretype end group for non-group") + return fmt.Errorf("proto: CompressedIdxAtt: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: ValidatorIDToIdxAtt: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: CompressedIdxAtt: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: @@ -1688,7 +1688,7 @@ func (m *ValidatorIDToIdxAtt) Unmarshal(dAtA []byte) error { } return nil } -func (m *ValidatorIDToIdxAttList) Unmarshal(dAtA []byte) error { +func (m *CompressedIdxAttList) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -1711,15 +1711,15 @@ func (m *ValidatorIDToIdxAttList) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: ValidatorIDToIdxAttList: wiretype end group for non-group") + return fmt.Errorf("proto: CompressedIdxAttList: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: ValidatorIDToIdxAttList: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: CompressedIdxAttList: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field IndicesList", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field List", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -1746,8 +1746,8 @@ func (m *ValidatorIDToIdxAttList) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.IndicesList = append(m.IndicesList, &ValidatorIDToIdxAtt{}) - if err := m.IndicesList[len(m.IndicesList)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + m.List = append(m.List, &CompressedIdxAtt{}) + if err := m.List[len(m.List)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex @@ -2677,6 +2677,7 @@ func (m *SlashingStatusRequest) Unmarshal(dAtA []byte) error { func skipSlashing(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 + depth := 0 for iNdEx < l { var wire uint64 for shift := uint(0); ; shift += 7 { @@ -2708,10 +2709,8 @@ func skipSlashing(dAtA []byte) (n int, err error) { break } } - return iNdEx, nil case 1: iNdEx += 8 - return iNdEx, nil case 2: var length int for shift := uint(0); ; shift += 7 { @@ -2732,55 +2731,30 @@ func skipSlashing(dAtA []byte) (n int, err error) { return 0, ErrInvalidLengthSlashing } iNdEx += length - if iNdEx < 0 { - return 0, ErrInvalidLengthSlashing - } - return iNdEx, nil case 3: - for { - var innerWire uint64 - var start int = iNdEx - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowSlashing - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - innerWire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - innerWireType := int(innerWire & 0x7) - if innerWireType == 4 { - break - } - next, err := skipSlashing(dAtA[start:]) - if err != nil { - return 0, err - } - iNdEx = start + next - if iNdEx < 0 { - return 0, ErrInvalidLengthSlashing - } - } - return iNdEx, nil + depth++ case 4: - return iNdEx, nil + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupSlashing + } + depth-- case 5: iNdEx += 4 - return iNdEx, nil default: return 0, fmt.Errorf("proto: illegal wireType %d", wireType) } + if iNdEx < 0 { + return 0, ErrInvalidLengthSlashing + } + if depth == 0 { + return iNdEx, nil + } } - panic("unreachable") + return 0, io.ErrUnexpectedEOF } var ( - ErrInvalidLengthSlashing = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowSlashing = fmt.Errorf("proto: integer overflow") + ErrInvalidLengthSlashing = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowSlashing = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupSlashing = fmt.Errorf("proto: unexpected end of group") ) diff --git a/proto/slashing/slashing.proto b/proto/slashing/slashing.proto index 11e4ffa057dc..1bf086410ea4 100644 --- a/proto/slashing/slashing.proto +++ b/proto/slashing/slashing.proto @@ -27,15 +27,19 @@ service Slasher { rpc AttesterSlashings(SlashingStatusRequest) returns (AttesterSlashingResponse); } -message ValidatorIDToIdxAtt { +// CompressedIdxAtt is an indexed attestation with the []byte data root +// in place of its AttestationData. +message CompressedIdxAtt { repeated uint64 indices = 1 ; bytes data_root = 2; // 96 bytes aggregate signature. bytes signature = 3; } -message ValidatorIDToIdxAttList { - repeated ValidatorIDToIdxAtt indicesList = 1 ; +// CompressedIdxAttList is a list of CompressedIdxAtts used for +// accessing an array from the DB. +message CompressedIdxAttList { + repeated CompressedIdxAtt list = 1; } message ProposerSlashingRequest { @@ -97,7 +101,7 @@ message SlashingStatusRequest { // Included slashing proof that has been included in a block. Included = 2; // Reverted slashing proof that has been reverted and therefore is relevant again. - Reverted = 3; + Reverted = 3; } SlashingStatus status = 1; } diff --git a/slasher/db/block_header.go b/slasher/db/block_header.go index 77606a1c2356..f795ab90b15c 100644 --- a/slasher/db/block_header.go +++ b/slasher/db/block_header.go @@ -20,9 +20,9 @@ func unmarshalBlockHeader(enc []byte) (*ethpb.SignedBeaconBlockHeader, error) { return protoBlockHeader, nil } -// BlockHeader accepts an epoch and validator id and returns the corresponding block header array. +// BlockHeaders accepts an epoch and validator id and returns the corresponding block header array. // Returns nil if the block header for those values does not exist. -func (db *Store) BlockHeader(epoch uint64, validatorID uint64) ([]*ethpb.SignedBeaconBlockHeader, error) { +func (db *Store) BlockHeaders(epoch uint64, validatorID uint64) ([]*ethpb.SignedBeaconBlockHeader, error) { var blockHeaders []*ethpb.SignedBeaconBlockHeader err := db.view(func(tx *bolt.Tx) error { c := tx.Bucket(historicBlockHeadersBucket).Cursor() diff --git a/slasher/db/block_header_test.go b/slasher/db/block_header_test.go index 3453b7d6781a..031a84f4aba6 100644 --- a/slasher/db/block_header_test.go +++ b/slasher/db/block_header_test.go @@ -24,7 +24,7 @@ func TestNilDBHistoryBlkHdr(t *testing.T) { t.Fatal("HasBlockHeader should return false") } - bPrime, err := db.BlockHeader(epoch, validatorID) + bPrime, err := db.BlockHeaders(epoch, validatorID) if err != nil { t.Fatalf("failed to get block: %v", err) } @@ -67,7 +67,7 @@ func TestSaveHistoryBlkHdr(t *testing.T) { t.Fatalf("save block failed: %v", err) } - bha, err := db.BlockHeader(tt.epoch, tt.vID) + bha, err := db.BlockHeaders(tt.epoch, tt.vID) if err != nil { t.Fatalf("failed to get block: %v", err) } @@ -115,7 +115,7 @@ func TestDeleteHistoryBlkHdr(t *testing.T) { } for _, tt := range tests { - bha, err := db.BlockHeader(tt.epoch, tt.vID) + bha, err := db.BlockHeaders(tt.epoch, tt.vID) if err != nil { t.Fatalf("failed to get block: %v", err) } @@ -127,7 +127,7 @@ func TestDeleteHistoryBlkHdr(t *testing.T) { if err != nil { t.Fatalf("save block failed: %v", err) } - bh, err := db.BlockHeader(tt.epoch, tt.vID) + bh, err := db.BlockHeaders(tt.epoch, tt.vID) if err != nil { t.Fatal(err) @@ -236,7 +236,7 @@ func TestPruneHistoryBlkHdr(t *testing.T) { t.Fatalf("save block header failed: %v", err) } - bha, err := db.BlockHeader(tt.epoch, tt.vID) + bha, err := db.BlockHeaders(tt.epoch, tt.vID) if err != nil { t.Fatalf("failed to get block header: %v", err) } @@ -253,7 +253,7 @@ func TestPruneHistoryBlkHdr(t *testing.T) { } for _, tt := range tests { - bha, err := db.BlockHeader(tt.epoch, tt.vID) + bha, err := db.BlockHeaders(tt.epoch, tt.vID) if err != nil { t.Fatalf("failed to get block header: %v", err) } diff --git a/slasher/db/db.go b/slasher/db/db.go index 46ba746dd485..5b0ac072ca8a 100644 --- a/slasher/db/db.go +++ b/slasher/db/db.go @@ -12,6 +12,9 @@ import ( ) var log = logrus.WithField("prefix", "slasherDB") + +var databaseFileName = "slasher.db" + var d *Store // Store defines an implementation of the Prysm Database interface @@ -53,12 +56,12 @@ func NewDB(dirPath string, cfg *Config) (*Store, error) { return d, err } -// ClearDB removes the previously stored directory at the data directory. +// ClearDB removes any previously stored data at the configured data directory. func (db *Store) ClearDB() error { if _, err := os.Stat(db.databasePath); os.IsNotExist(err) { return nil } - return os.RemoveAll(db.databasePath) + return os.Remove(db.databasePath) } // DatabasePath at which this database writes files. @@ -82,7 +85,7 @@ func NewKVStore(dirPath string, cfg *Config) (*Store, error) { if err := os.MkdirAll(dirPath, 0700); err != nil { return nil, err } - datafile := path.Join(dirPath, "slasher.db") + datafile := path.Join(dirPath, databaseFileName) boltDB, err := bolt.Open(datafile, 0600, &bolt.Options{Timeout: 1 * time.Second}) if err != nil { if err == bolt.ErrTimeout { @@ -103,17 +106,16 @@ func NewKVStore(dirPath string, cfg *Config) (*Store, error) { OnEvict: saveToDB, }) if err != nil { - errors.Wrap(err, "failed to start span cache") - return nil, err + return nil, errors.Wrap(err, "failed to start span cache") } - kv := &Store{db: boltDB, databasePath: dirPath, spanCache: spanCache, spanCacheEnabled: cfg.SpanCacheEnabled} + kv := &Store{db: boltDB, databasePath: datafile, spanCache: spanCache, spanCacheEnabled: cfg.SpanCacheEnabled} if err := kv.db.Update(func(tx *bolt.Tx) error { return createBuckets( tx, historicIndexedAttestationsBucket, historicBlockHeadersBucket, - indexedAttestationsIndicesBucket, + compressedIdxAttsBucket, validatorsPublicKeysBucket, validatorsMinMaxSpanBucket, slashingBucket, diff --git a/slasher/db/indexed_attestations.go b/slasher/db/indexed_attestations.go index 27ebbd95f429..17c61239e03f 100644 --- a/slasher/db/indexed_attestations.go +++ b/slasher/db/indexed_attestations.go @@ -25,8 +25,8 @@ func unmarshalIdxAtt(enc []byte) (*ethpb.IndexedAttestation, error) { return protoIdxAtt, nil } -func unmarshalValIDsToIdxAttList(enc []byte) (*slashpb.ValidatorIDToIdxAttList, error) { - protoIdxAtt := &slashpb.ValidatorIDToIdxAttList{} +func unmarshalCompressedIdxAttList(enc []byte) (*slashpb.CompressedIdxAttList, error) { + protoIdxAtt := &slashpb.CompressedIdxAttList{} err := proto.Unmarshal(enc, protoIdxAtt) if err != nil { return nil, errors.Wrap(err, "failed to unmarshal encoding") @@ -41,17 +41,17 @@ func (db *Store) IdxAttsForTargetFromID(targetEpoch uint64, validatorID uint64) var idxAtts []*ethpb.IndexedAttestation err := db.view(func(tx *bolt.Tx) error { - bucket := tx.Bucket(indexedAttestationsIndicesBucket) + bucket := tx.Bucket(compressedIdxAttsBucket) enc := bucket.Get(bytesutil.Bytes8(targetEpoch)) if enc == nil { return nil } - idToIdxAttsList, err := unmarshalValIDsToIdxAttList(enc) + idToIdxAttsList, err := unmarshalCompressedIdxAttList(enc) if err != nil { return err } - for _, idxAtt := range idToIdxAttsList.IndicesList { + for _, idxAtt := range idToIdxAttsList.List { i := sort.Search(len(idxAtt.Indices), func(i int) bool { return idxAtt.Indices[i] >= validatorID }) @@ -116,7 +116,7 @@ func (db *Store) LatestIndexedAttestationsTargetEpoch() (uint64, error) { func (db *Store) LatestValidatorIdx() (uint64, error) { var lt uint64 err := db.view(func(tx *bolt.Tx) error { - c := tx.Bucket(indexedAttestationsIndicesBucket).Cursor() + c := tx.Bucket(compressedIdxAttsBucket).Cursor() k, _ := c.Last() if k == nil { return nil @@ -167,16 +167,16 @@ func (db *Store) HasIndexedAttestation(targetEpoch uint64, validatorID uint64) ( var hasAttestation bool // #nosec G104 err := db.view(func(tx *bolt.Tx) error { - bucket := tx.Bucket(indexedAttestationsIndicesBucket) + bucket := tx.Bucket(compressedIdxAttsBucket) enc := bucket.Get(key) if enc == nil { return nil } - iList, err := unmarshalValIDsToIdxAttList(enc) + iList, err := unmarshalCompressedIdxAttList(enc) if err != nil { return err } - for _, idxAtt := range iList.IndicesList { + for _, idxAtt := range iList.List { i := sort.Search(len(idxAtt.Indices), func(i int) bool { return idxAtt.Indices[i] >= validatorID }) @@ -205,7 +205,7 @@ func (db *Store) SaveIndexedAttestation(idxAttestation *ethpb.IndexedAttestation if val != nil { return nil } - if err := saveIdxAttIndicesByEpochToDB(idxAttestation, tx); err != nil { + if err := saveCompressedIdxAttToEpochList(idxAttestation, tx); err != nil { return errors.Wrap(err, "failed to save indices from indexed attestation") } if err := bucket.Put(key, enc); err != nil { @@ -225,26 +225,26 @@ func (db *Store) SaveIndexedAttestation(idxAttestation *ethpb.IndexedAttestation return err } -func saveIdxAttIndicesByEpochToDB(idxAttestation *ethpb.IndexedAttestation, tx *bolt.Tx) error { +func saveCompressedIdxAttToEpochList(idxAttestation *ethpb.IndexedAttestation, tx *bolt.Tx) error { dataRoot, err := hashutil.HashProto(idxAttestation.Data) if err != nil { return errors.Wrap(err, "failed to hash indexed attestation data.") } - protoIdxAtt := &slashpb.ValidatorIDToIdxAtt{ + protoIdxAtt := &slashpb.CompressedIdxAtt{ Signature: idxAttestation.Signature, Indices: idxAttestation.AttestingIndices, DataRoot: dataRoot[:], } key := bytesutil.Bytes8(idxAttestation.Data.Target.Epoch) - bucket := tx.Bucket(indexedAttestationsIndicesBucket) + bucket := tx.Bucket(compressedIdxAttsBucket) enc := bucket.Get(key) - vIdxList, err := unmarshalValIDsToIdxAttList(enc) + compressedIdxAttList, err := unmarshalCompressedIdxAttList(enc) if err != nil { - return errors.Wrap(err, "failed to decode value into ValidatorIDToIndexedAttestationList") + return errors.Wrap(err, "failed to decode value into CompressedIdxAtt") } - vIdxList.IndicesList = append(vIdxList.IndicesList, protoIdxAtt) - enc, err = proto.Marshal(vIdxList) + compressedIdxAttList.List = append(compressedIdxAttList.List, protoIdxAtt) + enc, err = proto.Marshal(compressedIdxAttList) if err != nil { return errors.Wrap(err, "failed to marshal") } @@ -281,26 +281,26 @@ func removeIdxAttIndicesByEpochFromDB(idxAttestation *ethpb.IndexedAttestation, if err != nil { return err } - protoIdxAtt := &slashpb.ValidatorIDToIdxAtt{ + protoIdxAtt := &slashpb.CompressedIdxAtt{ Signature: idxAttestation.Signature, Indices: idxAttestation.AttestingIndices, DataRoot: dataRoot[:], } key := bytesutil.Bytes8(idxAttestation.Data.Target.Epoch) - bucket := tx.Bucket(indexedAttestationsIndicesBucket) + bucket := tx.Bucket(compressedIdxAttsBucket) enc := bucket.Get(key) if enc == nil { return errors.New("requested to delete data that is not present") } - vIdxList, err := unmarshalValIDsToIdxAttList(enc) + vIdxList, err := unmarshalCompressedIdxAttList(enc) if err != nil { return errors.Wrap(err, "failed to decode value into ValidatorIDToIndexedAttestationList") } - for i, attIdx := range vIdxList.IndicesList { + for i, attIdx := range vIdxList.List { if reflect.DeepEqual(attIdx, protoIdxAtt) { - copy(vIdxList.IndicesList[i:], vIdxList.IndicesList[i+1:]) - vIdxList.IndicesList[len(vIdxList.IndicesList)-1] = nil // or the zero value of T - vIdxList.IndicesList = vIdxList.IndicesList[:len(vIdxList.IndicesList)-1] + copy(vIdxList.List[i:], vIdxList.List[i+1:]) + vIdxList.List[len(vIdxList.List)-1] = nil // or the zero value of T + vIdxList.List = vIdxList.List[:len(vIdxList.List)-1] break } } @@ -330,8 +330,8 @@ func (db *Store) pruneAttHistory(currentEpoch uint64, historySize uint64) error } } - idxBucket := tx.Bucket(indexedAttestationsIndicesBucket) - c = tx.Bucket(indexedAttestationsIndicesBucket).Cursor() + idxBucket := tx.Bucket(compressedIdxAttsBucket) + c = tx.Bucket(compressedIdxAttsBucket).Cursor() for k, _ := c.First(); k != nil && bytes.Compare(k[:8], max) <= 0; k, _ = c.Next() { if err := idxBucket.Delete(k); err != nil { return errors.Wrap(err, "failed to delete indexed attestation from historical bucket") diff --git a/slasher/db/schema.go b/slasher/db/schema.go index 4f390bd99566..5ee1210d7939 100644 --- a/slasher/db/schema.go +++ b/slasher/db/schema.go @@ -11,7 +11,7 @@ var ( historicIndexedAttestationsBucket = []byte("historic-indexed-attestations-bucket") historicBlockHeadersBucket = []byte("historic-block-headers-bucket") slashingBucket = []byte("slashing-bucket") - indexedAttestationsIndicesBucket = []byte("indexed-attestations-indices-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. diff --git a/slasher/rpc/server.go b/slasher/rpc/server.go index adf05835ffb2..7a7fc40a7e08 100644 --- a/slasher/rpc/server.go +++ b/slasher/rpc/server.go @@ -141,7 +141,7 @@ func (ss *Server) UpdateSpanMaps(ctx context.Context, req *ethpb.IndexedAttestat func (ss *Server) IsSlashableBlock(ctx context.Context, psr *slashpb.ProposerSlashingRequest) (*slashpb.ProposerSlashingResponse, error) { //TODO(#3133): add signature validation epoch := helpers.SlotToEpoch(psr.BlockHeader.Header.Slot) - blockHeaders, err := ss.SlasherDB.BlockHeader(epoch, psr.ValidatorIndex) + blockHeaders, err := ss.SlasherDB.BlockHeaders(epoch, psr.ValidatorIndex) if err != nil { return nil, errors.Wrap(err, "slasher service error while trying to retrieve blocks") } diff --git a/slasher/service/BUILD.bazel b/slasher/service/BUILD.bazel index 68f06ec20ca6..8518301c1f3a 100644 --- a/slasher/service/BUILD.bazel +++ b/slasher/service/BUILD.bazel @@ -14,6 +14,7 @@ go_library( "//shared/cmd:go_default_library", "//shared/debug:go_default_library", "//shared/params:go_default_library", + "//shared/sliceutil:go_default_library", "//shared/version:go_default_library", "//slasher/db:go_default_library", "//slasher/flags:go_default_library", diff --git a/slasher/service/data_update.go b/slasher/service/data_update.go index e417b57a3923..b1cee4c6f10f 100644 --- a/slasher/service/data_update.go +++ b/slasher/service/data_update.go @@ -1,6 +1,7 @@ package service import ( + "context" "fmt" "time" @@ -9,77 +10,107 @@ import ( ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1" "github.com/prysmaticlabs/prysm/shared/attestationutil" "github.com/prysmaticlabs/prysm/shared/params" + "github.com/prysmaticlabs/prysm/shared/sliceutil" "github.com/prysmaticlabs/prysm/slasher/db" + "github.com/sirupsen/logrus" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" ) -// finalizedChangeUpdater this is a stub for the coming PRs #3133 -// Store validator index to public key map Validate attestation signature. -func (s *Service) finalizedChangeUpdater() error { - secondsPerSlot := params.BeaconConfig().SecondsPerSlot - d := time.Duration(secondsPerSlot) * time.Second - tick := time.Tick(d) - var finalizedEpoch uint64 - for { - select { - case <-tick: - ch, err := s.beaconClient.GetChainHead(s.context, &ptypes.Empty{}) - if err != nil { +// historicalAttestationFeeder starts performing slashing detection +// on all historical attestations made until the current head. +// The latest epoch is updated after each iteration in case the long +// process is interrupted. +func (s *Service) historicalAttestationFeeder() error { + startFromEpoch, err := s.getLatestDetectedEpoch() + if err != nil { + return errors.Wrap(err, "failed to latest detected epoch") + } + ch, err := s.getChainHead() + if err != nil { + return errors.Wrap(err, "failed to get chain head") + } + + for epoch := startFromEpoch; epoch < ch.FinalizedEpoch; epoch++ { + atts, bCommittees, err := s.attsAndCommitteesForEpoch(epoch) + if err != nil || bCommittees == nil { + log.Error(err) + continue + } + log.Infof("Checking %v attestations from epoch %v for slashable events", len(atts), epoch) + for _, attestation := range atts { + idxAtt, err := convertToIndexed(s.context, attestation, bCommittees) + if err = s.detectSlashings(idxAtt); err != nil { log.Error(err) continue } - if ch != nil { - if ch.FinalizedEpoch > finalizedEpoch { - log.Infof("finalized epoch %d", ch.FinalizedEpoch) - } - continue - } - log.Error("no chain head was returned by beacon chain.") - case <-s.context.Done(): - err := status.Error(codes.Canceled, "Stream context canceled") - log.WithError(err) - return err - + } + if err := s.slasherDb.SetLatestEpochDetected(epoch); err != nil { + log.Error(err) + continue } } + return nil } // attestationFeeder feeds attestations that were received by archive endpoint. func (s *Service) attestationFeeder() error { as, err := s.beaconClient.StreamAttestations(s.context, &ptypes.Empty{}) if err != nil { - log.WithError(err).Errorf("failed to retrieve attestation stream") - return err + return errors.Wrap(err, "failed to retrieve attestation stream") } for { select { default: if as == nil { - err := fmt.Errorf("attestation stream is nil. please check your archiver node status") - log.WithError(err) - return err + return fmt.Errorf("attestation stream is nil. please check your archiver node status") } - at, err := as.Recv() + att, err := as.Recv() if err != nil { - log.WithError(err) return err } committeeReq := ðpb.ListCommitteesRequest{ QueryFilter: ðpb.ListCommitteesRequest_Epoch{ - Epoch: at.Data.Target.Epoch, + Epoch: att.Data.Target.Epoch, }, } bCommittees, err := s.beaconClient.ListBeaconCommittees(s.context, committeeReq) if err != nil { - log.WithError(err).Errorf("Could not list beacon committees for epoch %d", at.Data.Target.Epoch) - return err + return errors.Wrapf(err, "could not list beacon committees for epoch %d", att.Data.Target.Epoch) + } + idxAtt, err := convertToIndexed(s.context, att, bCommittees) + if err = s.detectSlashings(idxAtt); err != nil { + log.Error(err) + continue } - err = s.detectAttestation(at, bCommittees) + log.Info("detected attestation for target: %d", att.Data.Target) + case <-s.context.Done(): + return status.Error(codes.Canceled, "Stream context canceled") + } + } +} + +// finalizedChangeUpdater this is a stub for the coming PRs #3133. +func (s *Service) finalizedChangeUpdater() error { + secondsPerSlot := params.BeaconConfig().SecondsPerSlot + d := time.Duration(secondsPerSlot) * time.Second + tick := time.Tick(d) + var finalizedEpoch uint64 + for { + select { + case <-tick: + ch, err := s.beaconClient.GetChainHead(s.context, &ptypes.Empty{}) if err != nil { + log.Error(err) continue } - log.Info("detected attestation for target: %d", at.Data.Target) + if ch != nil { + if ch.FinalizedEpoch > finalizedEpoch { + log.Infof("finalized epoch %d", ch.FinalizedEpoch) + } + continue + } + log.Error("no chain head was returned by beacon chain.") case <-s.context.Done(): err := status.Error(codes.Canceled, "Stream context canceled") log.WithError(err) @@ -88,90 +119,63 @@ func (s *Service) attestationFeeder() error { } } -// slasherOldAttestationFeeder a function to kick start slashing detection -// after all the included attestations in the canonical chain have been -// slashing detected. latest epoch is being updated after each iteration -// in case it changed during the detection process. -func (s *Service) slasherOldAttestationFeeder() error { - ch, err := s.getChainHead() - if err != nil { - return err - } - errOut := make(chan error) - startFromEpoch, err := s.getLatestDetectedEpoch() +func (s *Service) detectSlashings(idxAtt *ethpb.IndexedAttestation) error { + attSlashingResp, err := s.slasher.IsSlashableAttestation(s.context, idxAtt) if err != nil { - return err + return errors.Wrap(err, "failed to check attestation") } - for epoch := startFromEpoch; epoch < ch.FinalizedEpoch; epoch++ { - ats, bcs, err := s.getDataForDetection(epoch) - if err != nil || bcs == nil { - log.Error(err) - continue + if len(attSlashingResp.AttesterSlashing) > 0 { + if err := s.slasherDb.SaveAttesterSlashings(db.Active, attSlashingResp.AttesterSlashing); err != nil { + return errors.Wrap(err, "failed to save attester slashings") } - log.Infof("Detecting slashable events on: %v attestations from epoch: %v", len(ats.Attestations), epoch) - for _, attestation := range ats.Attestations { - if err := s.detectAttestation(attestation, bcs); err != nil { - continue - } + for _, as := range attSlashingResp.AttesterSlashing { + slashableIndices := sliceutil.IntersectionUint64(as.Attestation_1.AttestingIndices, as.Attestation_2.AttestingIndices) + log.WithFields(logrus.Fields{ + "target1": as.Attestation_1.Data.Target.Epoch, + "source1": as.Attestation_1.Data.Target.Epoch, + "target2": as.Attestation_2.Data.Target.Epoch, + "source2": as.Attestation_2.Data.Target.Epoch, + "slashableIndices": slashableIndices, + }).Info("Detected slashing offence") } - if err := s.slasherDb.SetLatestEpochDetected(epoch); err != nil { - log.Error(err) - continue - } - } - close(errOut) - for err := range errOut { - log.Error(errors.Wrap(err, "error while writing to db in background")) } return nil } -func (s *Service) detectAttestation(attestation *ethpb.Attestation, beaconCommittee *ethpb.BeaconCommittees) error { - slotCommittees, ok := beaconCommittee.Committees[attestation.Data.Slot] +func convertToIndexed(ctx context.Context, att *ethpb.Attestation, bCommittee *ethpb.BeaconCommittees) (*ethpb.IndexedAttestation, error) { + slotCommittees, ok := bCommittee.Committees[att.Data.Slot] if !ok || slotCommittees == nil { - err := fmt.Errorf("beacon committees object doesnt contain the attestation slot: %d, number of committees: %d", - attestation.Data.Slot, len(beaconCommittee.Committees)) - log.WithError(err) - return err - } - if attestation.Data.CommitteeIndex > uint64(len(slotCommittees.Committees)) { - err := fmt.Errorf("committee index is out of range in slot wanted: %d, actual: %d", attestation.Data.CommitteeIndex, len(slotCommittees.Committees)) - log.WithError(err) - return err - } - attesterCommittee := slotCommittees.Committees[attestation.Data.CommitteeIndex] - validatorIndices := attesterCommittee.ValidatorIndices - ia, err := attestationutil.ConvertToIndexed(s.context, attestation, validatorIndices) - if err != nil { - log.WithError(err) - return err - } - sar, err := s.slasher.IsSlashableAttestation(s.context, ia) + return nil, fmt.Errorf( + "could not get commitees for att slot: %d, number of committees: %d", + att.Data.Slot, + len(bCommittee.Committees), + ) + } + if att.Data.CommitteeIndex > uint64(len(slotCommittees.Committees)) { + return nil, fmt.Errorf( + "committee index is out of range in slot wanted: %d, actual: %d", + att.Data.CommitteeIndex, + len(slotCommittees.Committees), + ) + } + attCommittee := slotCommittees.Committees[att.Data.CommitteeIndex] + validatorIndices := attCommittee.ValidatorIndices + idxAtt, err := attestationutil.ConvertToIndexed(ctx, att, validatorIndices) if err != nil { - log.WithError(err) - return err - } - if err := s.slasherDb.SaveAttesterSlashings(db.Active, sar.AttesterSlashing); err != nil { - log.WithError(err) - return err - } - if len(sar.AttesterSlashing) > 0 { - for _, as := range sar.AttesterSlashing { - log.WithField("attesterSlashing", as).Info("detected slashing offence") - } + return nil, err } - return nil + return idxAtt, nil } -func (s *Service) getDataForDetection(epoch uint64) (*ethpb.ListAttestationsResponse, *ethpb.BeaconCommittees, error) { - ats, err := s.beaconClient.ListAttestations(s.context, ðpb.ListAttestationsRequest{ +func (s *Service) attsAndCommitteesForEpoch(epoch uint64) ([]*ethpb.Attestation, *ethpb.BeaconCommittees, error) { + attResp, err := s.beaconClient.ListAttestations(s.context, ðpb.ListAttestationsRequest{ QueryFilter: ðpb.ListAttestationsRequest_TargetEpoch{TargetEpoch: epoch}, }) if err != nil { log.WithError(err).Errorf("Could not list attestations for epoch: %d", epoch) } - bcs, err := s.beaconClient.ListBeaconCommittees(s.context, ðpb.ListCommitteesRequest{ + bCommittees, err := s.beaconClient.ListBeaconCommittees(s.context, ðpb.ListCommitteesRequest{ QueryFilter: ðpb.ListCommitteesRequest_Epoch{ Epoch: epoch, }, @@ -179,13 +183,12 @@ func (s *Service) getDataForDetection(epoch uint64) (*ethpb.ListAttestationsResp if err != nil { log.WithError(err).Errorf("Could not list beacon committees for epoch: %d", epoch) } - return ats, bcs, err + return attResp.Attestations, bCommittees, err } func (s *Service) getLatestDetectedEpoch() (uint64, error) { e, err := s.slasherDb.GetLatestEpochDetected() if err != nil { - log.Error(err) return 0, err } return e, nil @@ -197,7 +200,6 @@ func (s *Service) getChainHead() (*ethpb.ChainHead, error) { } ch, err := s.beaconClient.GetChainHead(s.context, &ptypes.Empty{}) if err != nil { - log.Error(err) return nil, err } if ch.FinalizedEpoch < 2 { diff --git a/slasher/service/service.go b/slasher/service/service.go index 231f8cb6bf53..32502a720973 100644 --- a/slasher/service/service.go +++ b/slasher/service/service.go @@ -95,6 +95,29 @@ func NewRPCService(cfg *Config, ctx *cli.Context) (*Service, error) { return s, nil } +func (s *Service) startDB(ctx *cli.Context) error { + baseDir := ctx.GlobalString(cmd.DataDirFlag.Name) + dbPath := path.Join(baseDir, slasherDBName) + cfg := &db.Config{SpanCacheEnabled: ctx.GlobalBool(flags.UseSpanCacheFlag.Name)} + d, err := db.NewDB(dbPath, cfg) + if err != nil { + return err + } + if s.ctx.GlobalBool(cmd.ClearDB.Name) { + if err := d.ClearDB(); err != nil { + return err + } + d, err = db.NewDB(dbPath, cfg) + if err != nil { + return err + } + } + + log.WithField("path", dbPath).Info("Checking db") + s.slasherDb = d + return nil +} + // Start the gRPC server. func (s *Service) Start() { s.lock.Lock() @@ -111,17 +134,24 @@ func (s *Service) Start() { } } stop := s.stop - err := s.slasherOldAttestationFeeder() - if err != nil { + if err := s.historicalAttestationFeeder(); err != nil { err = errors.Wrap(err, "couldn't start attestation feeder from archive endpoint. please use "+ "--beacon-rpc-provider flag value if you are not running a beacon chain service with "+ "--archive flag on the local machine.") - log.WithError(err) + log.Error(err) s.failStatus = err return } - go s.attestationFeeder() - go s.finalizedChangeUpdater() + go func() { + if err := s.attestationFeeder(); err != nil { + log.Error(err) + } + }() + go func() { + if err := s.finalizedChangeUpdater(); err != nil { + log.Error(err) + } + }() s.lock.Unlock() go func() { @@ -143,7 +173,6 @@ func (s *Service) Start() { s.started = true // Wait for stop channel to be closed. <-stop - } func (s *Service) startSlasher() { @@ -199,25 +228,6 @@ func (s *Service) startSlasher() { }() } -func (s *Service) loadSpanMaps(slasherServer rpc.Server) { - latestTargetEpoch, err := slasherServer.SlasherDB.LatestIndexedAttestationsTargetEpoch() - if err != nil { - log.Errorf("Could not extract latest target epoch from indexed attestations store: %v", err) - } - for epoch := uint64(0); epoch < latestTargetEpoch; epoch++ { - idxAtts, err := slasherServer.SlasherDB.IdxAttsForTarget(epoch) - if err != nil { - log.Errorf("Got error while trying to retrieve indexed attestations from db: %v", err) - } - for _, ia := range idxAtts { - if err := slasherServer.UpdateSpanMaps(s.context, ia); err != nil { - log.Errorf("Unexpected error updating span maps: %v", err) - } - } - log.Infof("Update span maps for epoch: %d", epoch) - } -} - func (s *Service) startBeaconClient() error { var dialOpt grpc.DialOption @@ -253,6 +263,25 @@ func (s *Service) startBeaconClient() error { return nil } +func (s *Service) loadSpanMaps(slasherServer rpc.Server) { + latestTargetEpoch, err := slasherServer.SlasherDB.LatestIndexedAttestationsTargetEpoch() + if err != nil { + log.Errorf("Could not extract latest target epoch from indexed attestations store: %v", err) + } + for epoch := uint64(0); epoch < latestTargetEpoch; epoch++ { + idxAtts, err := slasherServer.SlasherDB.IdxAttsForTarget(epoch) + if err != nil { + log.Errorf("Got error while trying to retrieve indexed attestations from db: %v", err) + } + for _, ia := range idxAtts { + if err := slasherServer.UpdateSpanMaps(s.context, ia); err != nil { + log.Errorf("Unexpected error updating span maps: %v", err) + } + } + log.Infof("Update span maps for epoch: %d", epoch) + } +} + // Stop the service. func (s *Service) Stop() error { log.Info("Stopping service") @@ -295,28 +324,4 @@ func (s *Service) Status() (bool, error) { return false, s.failStatus } return s.started, nil - -} - -func (s *Service) startDB(ctx *cli.Context) error { - baseDir := ctx.GlobalString(cmd.DataDirFlag.Name) - dbPath := path.Join(baseDir, slasherDBName) - cfg := &db.Config{SpanCacheEnabled: ctx.GlobalBool(flags.UseSpanCacheFlag.Name)} - d, err := db.NewDB(dbPath, cfg) - if err != nil { - return err - } - if s.ctx.GlobalBool(cmd.ClearDB.Name) { - if err := d.ClearDB(); err != nil { - return err - } - d, err = db.NewDB(dbPath, cfg) - if err != nil { - return err - } - } - - log.WithField("path", dbPath).Info("Checking db") - s.slasherDb = d - return nil } diff --git a/validator/db/db.go b/validator/db/db.go index 4aaf9bb36617..dc637eb33c16 100644 --- a/validator/db/db.go +++ b/validator/db/db.go @@ -43,7 +43,7 @@ func (db *Store) view(fn func(*bolt.Tx) error) error { return db.db.View(fn) } -// ClearDB removes the previously stored directory at the data directory. +// ClearDB removes any previously stored data at the configured data directory. func (db *Store) ClearDB() error { if _, err := os.Stat(db.databasePath); os.IsNotExist(err) { return nil