Browse Source

nil bugs

pull/9/head
Jae Kwon 10 years ago
parent
commit
5f794d14fb
5 changed files with 27 additions and 12 deletions
  1. +12
    -4
      blocks/part_set.go
  2. +2
    -2
      consensus/reactor.go
  3. +2
    -2
      consensus/state.go
  4. +8
    -1
      consensus/vote_set.go
  5. +3
    -3
      state/state_test.go

+ 12
- 4
blocks/part_set.go View File

@ -101,14 +101,14 @@ func (psh PartSetHeader) WriteTo(w io.Writer) (n int64, err error) {
return
}
func (psh PartSetHeader) IsZero() bool {
return psh.Total == 0
}
func (psh PartSetHeader) String() string {
return fmt.Sprintf("PartSet{%X/%v}", psh.Hash, psh.Total)
}
func (psh PartSetHeader) IsZero() bool {
return psh.Total == 0
}
func (psh PartSetHeader) Equals(other PartSetHeader) bool {
return psh.Total == other.Total && bytes.Equal(psh.Hash, other.Hash)
}
@ -179,6 +179,14 @@ func (ps *PartSet) Header() PartSetHeader {
}
}
func (ps *PartSet) HasHeader(header PartSetHeader) bool {
if ps == nil {
return false
} else {
return ps.Header().Equals(header)
}
}
func (ps *PartSet) BitArray() BitArray {
ps.mtx.Lock()
defer ps.mtx.Unlock()


+ 2
- 2
consensus/reactor.go View File

@ -252,7 +252,7 @@ OUTER_LOOP:
// Send proposal Block parts?
// NOTE: if we or peer is at RoundStepCommit*, the round
// won't necessarily match, but that's OK.
if rs.ProposalBlockParts.Header().Equals(prs.ProposalBlockParts) {
if rs.ProposalBlockParts.HasHeader(prs.ProposalBlockParts) {
if index, ok := rs.ProposalBlockParts.BitArray().Sub(
prs.ProposalBlockBitArray).PickRandom(); ok {
msg := &PartMessage{
@ -282,7 +282,7 @@ OUTER_LOOP:
}
// Send proposal POL parts?
if rs.ProposalPOLParts.Header().Equals(prs.ProposalPOLParts) {
if rs.ProposalPOLParts.HasHeader(prs.ProposalPOLParts) {
if index, ok := rs.ProposalPOLParts.BitArray().Sub(
prs.ProposalPOLBitArray).PickRandom(); ok {
msg := &PartMessage{


+ 2
- 2
consensus/state.go View File

@ -676,7 +676,7 @@ func (cs *ConsensusState) RunActionCommit(height uint32) {
// If we don't have the block being committed, set up to get it.
if !cs.ProposalBlock.HashesTo(hash) {
if !cs.ProposalBlockParts.Header().Equals(partsHeader) {
if !cs.ProposalBlockParts.HasHeader(partsHeader) {
// We're getting the wrong block.
// Set up ProposalBlockParts and keep waiting.
cs.ProposalBlock = nil
@ -720,7 +720,7 @@ func (cs *ConsensusState) TryFinalizeCommit(height uint32) bool {
if !cs.ProposalBlock.HashesTo(hash) {
Panicf("Expected ProposalBlock to hash to commit hash")
}
if !cs.ProposalBlockParts.Header().Equals(header) {
if !cs.ProposalBlockParts.HasHeader(header) {
Panicf("Expected ProposalBlockParts header to be commit header")
}


+ 8
- 1
consensus/vote_set.go View File

@ -55,7 +55,11 @@ func NewVoteSet(height uint32, round uint16, type_ byte, vset *state.ValidatorSe
}
func (vs *VoteSet) Size() uint {
return vs.vset.Size()
if vs == nil {
return 0
} else {
return vs.vset.Size()
}
}
// True if added, false if not.
@ -132,6 +136,9 @@ func (vs *VoteSet) AddFromCommits(commits *VoteSet) {
}
func (vs *VoteSet) BitArray() BitArray {
if vs == nil {
return BitArray{}
}
vs.mtx.Lock()
defer vs.mtx.Unlock()
return vs.votesBitArray.Copy()


+ 3
- 3
state/state_test.go View File

@ -85,7 +85,7 @@ func TestGenesisSaveLoad(t *testing.T) {
s0, _ := randGenesisState(10, 5)
// Mutate the state to append one empty block.
block := &Block{
Header: Header{
Header: &Header{
Network: Config.Network,
Height: 1,
Time: s0.LastBlockTime.Add(time.Minute),
@ -94,8 +94,8 @@ func TestGenesisSaveLoad(t *testing.T) {
LastBlockParts: s0.LastBlockParts,
StateHash: nil,
},
Validation: Validation{},
Data: Data{
Validation: &Validation{},
Data: &Data{
Txs: []Tx{},
},
}


Loading…
Cancel
Save