Skip to content

Commit

Permalink
Address Nina's feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
tholonious committed Jun 25, 2023
1 parent fa52ecf commit d798c71
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 15 deletions.
8 changes: 4 additions & 4 deletions lib/block_view_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -4659,22 +4659,22 @@ func EncodeUint64Array(uint64s []uint64) []byte {
}

func DecodeUint64Array(reader io.Reader) ([]uint64, error) {
pkLen, err := ReadUvarint(reader)
arrLen, err := ReadUvarint(reader)
if err != nil {
return nil, errors.Wrapf(err, "DecodeUint64Array: Problem reading array length")
}

if pkLen <= 0 {
if arrLen <= 0 {
return nil, nil
}

var result []uint64
result, err = SafeMakeSliceWithLength[uint64](pkLen)
result, err = SafeMakeSliceWithLength[uint64](arrLen)
if err != nil {
return nil, errors.Wrapf(err, "DecodeUint64Array: Problem creating slice")
}

for ii := uint64(0); ii < pkLen; ii++ {
for ii := uint64(0); ii < arrLen; ii++ {
result[ii], err = ReadUvarint(reader)
if err != nil {
return nil, errors.Wrapf(err, "DecodeUint64Array: Problem reading uint64")
Expand Down
8 changes: 5 additions & 3 deletions lib/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,11 @@ const (
NetworkType_TESTNET NetworkType = 2
)

type MsgDeSoHeaderVersion = uint32

const (
// This is the header version that the blockchain started with.
HeaderVersion0 = uint32(0)
HeaderVersion0 = MsgDeSoHeaderVersion(0)
// This version made several changes to the previous header encoding format:
// - The Nonce field was expanded to 64 bits
// - Another ExtraNonce field was added to provide *another* 64 bits of entropy,
Expand All @@ -101,7 +103,7 @@ const (
//
// At the time of this writing, the intent is to deploy it in a backwards-compatible
// fashion, with the eventual goal of phasing out blocks with the previous version.
HeaderVersion1 = uint32(1)
HeaderVersion1 = MsgDeSoHeaderVersion(1)
// This version introduces the transition from Proof of Work to Proof of Stake blocks.
// It includes several changes to the header format:
// - Nonce field is deprecated
Expand All @@ -111,7 +113,7 @@ const (
//
// This format change is a breaking change that is not backwards-compatible with
// versions 0 and 1.
HeaderVersion2 = uint32(2)
HeaderVersion2 = MsgDeSoHeaderVersion(2)
// This CurrentHeaderVersion is an implicit version type that represents the latest
// backwards compatible Proof of Work header format. This value is now locked to
// HeaderVersion1 since versions 2 and onwards will be used for Proof of Stake formats.
Expand Down
6 changes: 2 additions & 4 deletions lib/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -2288,18 +2288,16 @@ func DecodeHeaderVersion2(rr io.Reader) (*MsgDeSoHeader, error) {
retHeader.ExtraNonce = 0

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

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

return retHeader, nil
}
Expand Down
18 changes: 14 additions & 4 deletions lib/pos_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ func DecodeAggregatedBLSSignature(rr io.Reader) (*AggregatedBLSSignature, error)
// of all validators, weighted by stake, which indicates that these validators want to
// time out a particular view.
//
// When validators want to time a view, they send their high QCs to the block proposer
// When validators want to time out a view, they send their high QCs to the block proposer
// who builds an aggregate QC extending the chain from the highest QC that it received
// from all validators who timed out. To prove that it has selected the highest QC, the
// proposer also includes a list of the high QC views that each validator has sent.
Expand Down Expand Up @@ -447,15 +447,25 @@ func (aggQC *TimeoutAggregateQuorumCertificate) Eq(
return false
}

if aggQC.TimedOutView != other.TimedOutView {
return false
}

if !aggQC.ValidatorsHighQC.Eq(other.ValidatorsHighQC) {
return false
}

if !aggQC.ValidatorsTimeoutAggregatedSignature.Eq(other.ValidatorsTimeoutAggregatedSignature) {
return false
}

for i := 0; i < len(aggQC.ValidatorsTimeoutHighQCViews); i++ {
if aggQC.ValidatorsTimeoutHighQCViews[i] != other.ValidatorsTimeoutHighQCViews[i] {
return false
}
}

return aggQC.TimedOutView == other.TimedOutView &&
aggQC.ValidatorsHighQC.Eq(other.ValidatorsHighQC) &&
aggQC.ValidatorsTimeoutAggregatedSignature.Eq(other.ValidatorsTimeoutAggregatedSignature)
return true
}

func (aggQC *TimeoutAggregateQuorumCertificate) ToBytes() ([]byte, error) {
Expand Down

0 comments on commit d798c71

Please sign in to comment.