Skip to content
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
16 changes: 16 additions & 0 deletions lib/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -1912,6 +1912,13 @@ type MsgDeSoHeader struct {
// event that ASICs become powerful enough to have birthday problems in the future.
ExtraNonce uint64

// ProposedInView is only used for Proof of Stake blocks, and will only be populated
// in MsgDeSoHeader versions 2 and higher. For all earlier version, this field will
// default to zero.
//
// Denotes the view in which this block was proposed.
ProposedInView uint64

// ValidatorsVoteQC is only used for Proof of Stake blocks, and will only be
// populated in MsgDeSoHeader versions 2 and higher. For all earlier version, this
// field will be null.
Expand Down Expand Up @@ -2090,6 +2097,9 @@ func (msg *MsgDeSoHeader) EncodeHeaderVersion2(preSignature bool) ([]byte, error
// The Nonce and ExtraNonce fields are unused in version 2. We skip them
// during both encoding and decoding.

// ProposedInView
retBytes = append(retBytes, EncodeUint64BigEndian(msg.ProposedInView)...)

// ValidatorsVoteQC
if msg.ValidatorsVoteQC == nil {
return nil, fmt.Errorf("EncodeHeaderVersion2: ValidatorsVoteQC must be non-nil")
Expand Down Expand Up @@ -2268,6 +2278,12 @@ func DecodeHeaderVersion2(rr io.Reader) (*MsgDeSoHeader, error) {
retHeader.Nonce = 0
retHeader.ExtraNonce = 0

// ProposedInView
retHeader.ProposedInView, err = DecodeUint64BigEndian(rr)
if err != nil {
return nil, errors.Wrapf(err, "MsgDeSoHeader.FromBytes: Problem decoding ProposedInView")
}

// ValidatorsVoteQC
retHeader.ValidatorsVoteQC, err = DecodeQuorumCertificate(rr)
if err != nil {
Expand Down
7 changes: 4 additions & 3 deletions lib/network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,9 @@ func createTestBlockHeaderVersion2(t *testing.T) *MsgDeSoHeader {
TstampSecs: uint64(1678943210),
Height: uint64(1321012345),
// Nonce and ExtraNonce are unused and set to 0 starting in version 2.
Nonce: uint64(0),
ExtraNonce: uint64(0),
Nonce: uint64(0),
ExtraNonce: uint64(0),
ProposedInView: uint64(1432101234),
// Use real signatures and public keys for the PoS fields
ValidatorsVoteQC: &QuorumCertificate{
BlockHash: &testBlockHash,
Expand Down Expand Up @@ -220,7 +221,7 @@ func TestHeaderConversionAndReadWriteMessage(t *testing.T) {
assert.NoError(err)
assert.Equal(hdrPayload, data)

assert.Equalf(9, reflect.TypeOf(expectedBlockHeader).Elem().NumField(),
assert.Equalf(10, reflect.TypeOf(expectedBlockHeader).Elem().NumField(),
"Number of fields in HEADER message is different from expected. "+
"Did you add a new field? If so, make sure the serialization code "+
"works, add the new field to the test case, and fix this error.")
Expand Down