-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Add and verify weak-subjectivity-checkpoint
flag
#7256
Merged
Merged
Changes from 3 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
61427a6
Handle weak subjectivity input
terencechain 272cb48
Typo
terencechain abef0fc
Merge branch 'master' into wsp-input
rauljordan 452d24a
Feedbacks
terencechain 5dd4ee1
Merge branch 'wsp-input' of github.com:prysmaticlabs/prysm into wsp-i…
terencechain 1de1c68
Merge refs/heads/master into wsp-input
prylabs-bulldozer[bot] 40df921
Merge refs/heads/master into wsp-input
prylabs-bulldozer[bot] 46b9a8a
Better error string @rauljordan
terencechain 245507c
Merge branch 'wsp-input' of github.com:prysmaticlabs/prysm into wsp-i…
terencechain 74913d7
Merge refs/heads/master into wsp-input
prylabs-bulldozer[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package node | ||
|
||
import ( | ||
"encoding/hex" | ||
"fmt" | ||
"strconv" | ||
"strings" | ||
) | ||
|
||
// Given input string `block_root:epoch_number`, this verifies the input string is valid, and | ||
// returns the block root as bytes and epoch number as unsigned integers. | ||
func convertWspInput(wsp string) ([]byte, uint64, error) { | ||
if wsp == "" { | ||
return nil, 0, nil | ||
} | ||
|
||
// Weak subjectivity input string must contain ":" to separate epoch and block root. | ||
if !strings.Contains(wsp, ":") { | ||
return nil, 0, fmt.Errorf("incorrect input %s did not contain column", wsp) | ||
} | ||
|
||
// Strip prefix "0x" if it's part of the input string. | ||
if strings.HasPrefix(wsp, "0x") { | ||
wsp = wsp[2:] | ||
} | ||
|
||
// Get the hexadecimal block root from input string. | ||
s := strings.Split(wsp, ":") | ||
bRoot, err := hex.DecodeString(s[0]) | ||
if err != nil { | ||
return nil, 0, err | ||
} | ||
|
||
// Get the epoch number from input string. | ||
epoch, err := strconv.ParseUint(s[1], 10, 64) | ||
if err != nil { | ||
return nil, 0, err | ||
} | ||
|
||
return bRoot, epoch, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package node | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
|
||
"github.com/prysmaticlabs/prysm/shared/testutil/require" | ||
) | ||
|
||
func TestConvertWspInput(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
input string | ||
bRoot []byte | ||
epoch uint64 | ||
wantErr bool | ||
errStr string | ||
}{ | ||
{ | ||
name: "No column in string", | ||
input: "0x111111;123", | ||
wantErr: true, | ||
errStr: "did not contain column", | ||
}, | ||
{ | ||
name: "Correct input #1", | ||
input: "0x010203:987", | ||
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. shouldnt the block root be 32 bytes. Lets add a check for it. |
||
bRoot: []byte{1, 2, 3}, | ||
epoch: 987, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "Correct input #2", | ||
input: "FFFFFFFFFFFFFFFFFF:123456789", | ||
bRoot: []byte{255, 255, 255, 255, 255, 255, 255, 255, 255}, | ||
epoch: 123456789, | ||
wantErr: false, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
bRoot, epoch, err := convertWspInput(tt.input) | ||
if (err != nil) != tt.wantErr { | ||
require.ErrorContains(t, tt.errStr, err) | ||
return | ||
} | ||
if !reflect.DeepEqual(bRoot, tt.bRoot) { | ||
t.Errorf("convertWspInput() block root = %v, want %v", bRoot, tt.bRoot) | ||
} | ||
if epoch != tt.epoch { | ||
t.Errorf("convertWspInput() epoch = %v, want %v", epoch, tt.epoch) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
what if len is < 2?
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.
Good point. I'll add a check