diff --git a/core/rawdb/accessors_chain.go b/core/rawdb/accessors_chain.go index 5a89f48d1e..7cf645c0e7 100644 --- a/core/rawdb/accessors_chain.go +++ b/core/rawdb/accessors_chain.go @@ -766,101 +766,6 @@ func DeleteReceipts(db ethdb.KeyValueWriter, hash common.Hash, number uint64) { } } -const badWorkObjectToKeep = 10 - -type badWorkObject struct { - woHeader *types.WorkObjectHeader - woBody *types.WorkObjectBody - tx types.Transaction -} - -// ProtoEncode returns the protobuf encoding of the bad workObject. -func (b badWorkObject) ProtoEncode() *ProtoBadWorkObject { - protoWorkObjectHeader, err := b.woHeader.ProtoEncode() - if err != nil { - log.Global.WithField("err", err).Fatal("Failed to proto encode header") - } - protoWorkObjectBody, err := b.woBody.ProtoEncode(types.BlockObject) - if err != nil { - log.Global.WithField("err", err).Fatal("Failed to proto encode body") - } - return &ProtoBadWorkObject{ - WoHeader: protoWorkObjectHeader, - WoBody: protoWorkObjectBody, - } -} - -// ProtoDecode decodes the protobuf encoding of the bad workObject. -func (b *badWorkObject) ProtoDecode(pb *ProtoBadWorkObject, location common.Location) error { - woHeader := new(types.WorkObjectHeader) - if err := woHeader.ProtoDecode(pb.WoHeader, location); err != nil { - return err - } - b.woHeader = woHeader - woBody := new(types.WorkObjectBody) - if err := woBody.ProtoDecode(pb.WoBody, b.woHeader.Location(), types.BlockObject); err != nil { - return err - } - b.woBody = woBody - return nil -} - -// badWorkObjectList implements the sort interface to allow sorting a list of -// bad blocks by their number in the reverse order. -type badWorkObjectList []*badWorkObject - -func (s badWorkObjectList) Len() int { return len(s) } -func (s badWorkObjectList) Less(i, j int) bool { - return s[i].woHeader.NumberU64() < s[j].woHeader.NumberU64() -} -func (s badWorkObjectList) Swap(i, j int) { s[i], s[j] = s[j], s[i] } - -func (s badWorkObjectList) ProtoEncode() *ProtoBadWorkObjects { - protoList := make([]*ProtoBadWorkObject, len(s)) - for i, bad := range s { - protoList[i] = bad.ProtoEncode() - } - return &ProtoBadWorkObjects{BadWorkObjects: protoList} -} - -func (s *badWorkObjectList) ProtoDecode(pb *ProtoBadWorkObjects, location common.Location) error { - list := make(badWorkObjectList, len(pb.BadWorkObjects)) - for i, protoBlock := range pb.BadWorkObjects { - block := new(badWorkObject) - if err := block.ProtoDecode(protoBlock, location); err != nil { - return err - } - list[i] = block - } - *s = list - return nil -} - -// ReadBadWorkObject retrieves the bad workObject with the corresponding workObject hash. -func ReadBadWorkObject(db ethdb.Reader, hash common.Hash) *types.WorkObject { - blob, err := db.Get(badWorkObjectKey) - if err != nil { - return nil - } - protoBadWorkObjects := new(ProtoBadWorkObjects) - err = proto.Unmarshal(blob, protoBadWorkObjects) - if err != nil { - return nil - } - - badWorkObjects := new(badWorkObjectList) - err = badWorkObjects.ProtoDecode(protoBadWorkObjects, db.Location()) - if err != nil { - return nil - } - for _, bad := range *badWorkObjects { - if bad.woHeader.Hash() == hash { - return types.NewWorkObject(bad.woHeader, bad.woBody, nil) - } - } - return nil -} - // FindCommonAncestor returns the last common ancestor of two block headers func FindCommonAncestor(db ethdb.Reader, a, b *types.WorkObject, nodeCtx int) *types.WorkObject { for bn := b.NumberU64(nodeCtx); a.NumberU64(nodeCtx) > bn; { diff --git a/core/rawdb/database.go b/core/rawdb/database.go index 47381186ad..3950007df8 100644 --- a/core/rawdb/database.go +++ b/core/rawdb/database.go @@ -433,7 +433,7 @@ func InspectDatabase(db ethdb.Database, keyPrefix, keyStart []byte, logger *log. databaseVersionKey, headHeaderKey, headWorkObjectKey, snapshotDisabledKey, snapshotRootKey, snapshotJournalKey, snapshotGeneratorKey, snapshotRecoveryKey, - uncleanShutdownKey, badWorkObjectKey, + uncleanShutdownKey, } { if bytes.Equal(key, meta) { metadata.Add(size) diff --git a/core/rawdb/db.pb.go b/core/rawdb/db.pb.go index 0085ce2c8f..02b6e4ca23 100644 --- a/core/rawdb/db.pb.go +++ b/core/rawdb/db.pb.go @@ -69,116 +69,6 @@ func (x *ProtoNumber) GetNumber() uint64 { return 0 } -type ProtoBadWorkObject struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - WoHeader *types.ProtoWorkObjectHeader `protobuf:"bytes,1,opt,name=wo_header,json=woHeader,proto3" json:"wo_header,omitempty"` - WoBody *types.ProtoWorkObjectBody `protobuf:"bytes,2,opt,name=wo_body,json=woBody,proto3" json:"wo_body,omitempty"` - Tx *types.ProtoTransaction `protobuf:"bytes,3,opt,name=tx,proto3" json:"tx,omitempty"` -} - -func (x *ProtoBadWorkObject) Reset() { - *x = ProtoBadWorkObject{} - if protoimpl.UnsafeEnabled { - mi := &file_core_rawdb_db_proto_msgTypes[1] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *ProtoBadWorkObject) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*ProtoBadWorkObject) ProtoMessage() {} - -func (x *ProtoBadWorkObject) ProtoReflect() protoreflect.Message { - mi := &file_core_rawdb_db_proto_msgTypes[1] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use ProtoBadWorkObject.ProtoReflect.Descriptor instead. -func (*ProtoBadWorkObject) Descriptor() ([]byte, []int) { - return file_core_rawdb_db_proto_rawDescGZIP(), []int{1} -} - -func (x *ProtoBadWorkObject) GetWoHeader() *types.ProtoWorkObjectHeader { - if x != nil { - return x.WoHeader - } - return nil -} - -func (x *ProtoBadWorkObject) GetWoBody() *types.ProtoWorkObjectBody { - if x != nil { - return x.WoBody - } - return nil -} - -func (x *ProtoBadWorkObject) GetTx() *types.ProtoTransaction { - if x != nil { - return x.Tx - } - return nil -} - -type ProtoBadWorkObjects struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - BadWorkObjects []*ProtoBadWorkObject `protobuf:"bytes,1,rep,name=bad_work_objects,json=badWorkObjects,proto3" json:"bad_work_objects,omitempty"` -} - -func (x *ProtoBadWorkObjects) Reset() { - *x = ProtoBadWorkObjects{} - if protoimpl.UnsafeEnabled { - mi := &file_core_rawdb_db_proto_msgTypes[2] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *ProtoBadWorkObjects) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*ProtoBadWorkObjects) ProtoMessage() {} - -func (x *ProtoBadWorkObjects) ProtoReflect() protoreflect.Message { - mi := &file_core_rawdb_db_proto_msgTypes[2] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use ProtoBadWorkObjects.ProtoReflect.Descriptor instead. -func (*ProtoBadWorkObjects) Descriptor() ([]byte, []int) { - return file_core_rawdb_db_proto_rawDescGZIP(), []int{2} -} - -func (x *ProtoBadWorkObjects) GetBadWorkObjects() []*ProtoBadWorkObject { - if x != nil { - return x.BadWorkObjects - } - return nil -} - type ProtoLegacyTxLookupEntry struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -298,8 +188,6 @@ func file_core_rawdb_db_proto_rawDescGZIP() []byte { var file_core_rawdb_db_proto_msgTypes = make([]protoimpl.MessageInfo, 4) var file_core_rawdb_db_proto_goTypes = []any{ (*ProtoNumber)(nil), // 0: db.ProtoNumber - (*ProtoBadWorkObject)(nil), // 1: db.ProtoBadWorkObject - (*ProtoBadWorkObjects)(nil), // 2: db.ProtoBadWorkObjects (*ProtoLegacyTxLookupEntry)(nil), // 3: db.ProtoLegacyTxLookupEntry (*types.ProtoWorkObjectHeader)(nil), // 4: block.ProtoWorkObjectHeader (*types.ProtoWorkObjectBody)(nil), // 5: block.ProtoWorkObjectBody @@ -307,10 +195,6 @@ var file_core_rawdb_db_proto_goTypes = []any{ (*common.ProtoHash)(nil), // 7: common.ProtoHash } var file_core_rawdb_db_proto_depIdxs = []int32{ - 4, // 0: db.ProtoBadWorkObject.wo_header:type_name -> block.ProtoWorkObjectHeader - 5, // 1: db.ProtoBadWorkObject.wo_body:type_name -> block.ProtoWorkObjectBody - 6, // 2: db.ProtoBadWorkObject.tx:type_name -> block.ProtoTransaction - 1, // 3: db.ProtoBadWorkObjects.bad_work_objects:type_name -> db.ProtoBadWorkObject 7, // 4: db.ProtoLegacyTxLookupEntry.hash:type_name -> common.ProtoHash 5, // [5:5] is the sub-list for method output_type 5, // [5:5] is the sub-list for method input_type @@ -337,30 +221,6 @@ func file_core_rawdb_db_proto_init() { return nil } } - file_core_rawdb_db_proto_msgTypes[1].Exporter = func(v any, i int) any { - switch v := v.(*ProtoBadWorkObject); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_core_rawdb_db_proto_msgTypes[2].Exporter = func(v any, i int) any { - switch v := v.(*ProtoBadWorkObjects); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } file_core_rawdb_db_proto_msgTypes[3].Exporter = func(v any, i int) any { switch v := v.(*ProtoLegacyTxLookupEntry); i { case 0: diff --git a/core/rawdb/db.proto b/core/rawdb/db.proto index cce42b7de7..180593cda2 100644 --- a/core/rawdb/db.proto +++ b/core/rawdb/db.proto @@ -8,16 +8,6 @@ import "common/proto_common.proto"; message ProtoNumber { uint64 number = 1; } -message ProtoBadWorkObject { - block.ProtoWorkObjectHeader wo_header = 1; - block.ProtoWorkObjectBody wo_body = 2; - block.ProtoTransaction tx = 3; -} - -message ProtoBadWorkObjects { - repeated ProtoBadWorkObject bad_work_objects = 1; -} - message ProtoLegacyTxLookupEntry { common.ProtoHash hash = 1; uint64 block_index = 2; diff --git a/core/rawdb/schema.go b/core/rawdb/schema.go index 1330b79cec..134e68f6ce 100644 --- a/core/rawdb/schema.go +++ b/core/rawdb/schema.go @@ -59,9 +59,6 @@ var ( // snapshotSyncStatusKey tracks the snapshot sync status across restarts. snapshotSyncStatusKey = []byte("SnapshotSyncStatus") - // badWorkObjectKey tracks the list of bad blocks seen by local - badWorkObjectKey = []byte("InvalidWorkObject") - // uncleanShutdownKey tracks the list of local crashes uncleanShutdownKey = []byte("unclean-shutdown") // config prefix for the db