-
Notifications
You must be signed in to change notification settings - Fork 116
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
fix(lib/blocktree): reimplement BestBlockHash
to take into account primary blocks in fork choice rule
#2254
Changes from 13 commits
acc43e6
f63f073
ab2e531
32d0c23
70fcf27
12e1e17
b76e211
16bc46f
bf26f04
a9e2c91
787790f
a79d5df
0ef9ea3
6b841f4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -114,3 +114,31 @@ func GetSlotFromHeader(header *Header) (uint64, error) { | |
|
||
return slotNumber, nil | ||
} | ||
|
||
// IsPrimary returns true if the block was authored in a primary slot, false otherwise. | ||
func IsPrimary(header *Header) (bool, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can make this a receiver function on |
||
if header == nil { | ||
return false, fmt.Errorf("cannot have nil header") | ||
} | ||
|
||
if len(header.Digest.Types) == 0 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should there be a nil check for header here as well? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah I can add it, hopefully doesn't happen though lol |
||
return false, fmt.Errorf("chain head missing digest") | ||
} | ||
|
||
preDigest, ok := header.Digest.Types[0].Value().(PreRuntimeDigest) | ||
if !ok { | ||
return false, fmt.Errorf("first digest item is not pre-digest: type=%T", header.Digest.Types[0].Value()) | ||
} | ||
|
||
digest, err := DecodeBabePreDigest(preDigest.Data) | ||
if err != nil { | ||
return false, fmt.Errorf("cannot decode BabePreDigest from pre-digest: %s", err) | ||
} | ||
|
||
switch digest.(type) { | ||
case BabePrimaryPreDigest: | ||
return true, nil | ||
default: | ||
return false, nil | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove
r
argument from function signature