Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove BadWorkObject and related methods #2008

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 0 additions & 95 deletions core/rawdb/accessors_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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; {
Expand Down
2 changes: 1 addition & 1 deletion core/rawdb/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
140 changes: 0 additions & 140 deletions core/rawdb/db.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 0 additions & 10 deletions core/rawdb/db.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 0 additions & 3 deletions core/rawdb/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading