Browse Source

cswal_light logs own votes; fix tests

pull/205/head
Ethan Buchman 9 years ago
parent
commit
922f720cf6
5 changed files with 14 additions and 10 deletions
  1. +3
    -2
      consensus/replay_test.go
  2. +1
    -1
      consensus/state_test.go
  3. +6
    -3
      consensus/wal.go
  4. +1
    -1
      types/part_set.go
  5. +3
    -3
      types/part_set_test.go

+ 3
- 2
consensus/replay_test.go View File

@ -80,19 +80,20 @@ func TestReplayCatchup(t *testing.T) {
// start timeout and receive routines
cs.startRoutines(0)
// cs.scheduleRound0(cs.Height)
// open wal and run catchup messages
openWAL(t, cs, name)
if err := cs.catchupReplay(cs.Height); err != nil {
t.Fatalf("Error on catchup replay %v", err)
}
after := time.After(time.Second * 2)
after := time.After(time.Second * 15)
select {
case <-newBlockCh:
case <-after:
t.Fatal("Timed out waiting for new block")
}
}
func openWAL(t *testing.T, cs *ConsensusState, file string) {


+ 1
- 1
consensus/state_test.go View File

@ -584,7 +584,7 @@ func TestLockPOLRelock(t *testing.T) {
t.Fatal("Expected height to increment")
}
if !bytes.Equal(b.Block.Hash(), propBlockHash) {
if !bytes.Equal(b.Block.Header.Hash(), propBlockHash) {
t.Fatal("Expected new block to be proposal block")
}
}


+ 6
- 3
consensus/wal.go View File

@ -64,9 +64,12 @@ func NewWAL(file string, light bool) (*WAL, error) {
func (wal *WAL) Save(clm ConsensusLogMessageInterface) {
if wal != nil {
if wal.light {
// in light mode we only write new steps and timeouts (no votes, proposals, block parts)
if _, ok := clm.(msgInfo); ok {
return
// in light mode we only write new steps, timeouts, and our own votes (no proposals, block parts)
if mi, ok := clm.(msgInfo); ok {
_ = mi
if mi.PeerKey != "" {
return
}
}
}
var n int


+ 1
- 1
types/part_set.go View File

@ -268,7 +268,7 @@ func (psr *PartSetReader) Read(p []byte) (n int, err error) {
psr.i += 1
if psr.i >= len(psr.parts) {
return 0, fmt.Errorf("Attempt to read from PartSet but no parts left")
return 0, io.EOF
}
psr.reader = bytes.NewReader(psr.parts[psr.i].Bytes)
return psr.Read(p)


+ 3
- 3
types/part_set_test.go View File

@ -30,7 +30,7 @@ func TestBasicPartSet(t *testing.T) {
for i := 0; i < partSet.Total(); i++ {
part := partSet.GetPart(i)
//t.Logf("\n%v", part)
added, err := partSet2.AddPart(part)
added, err := partSet2.AddPart(part, true)
if !added || err != nil {
t.Errorf("Failed to add part %v, error: %v", i, err)
}
@ -70,7 +70,7 @@ func TestWrongProof(t *testing.T) {
// Test adding a part with wrong trail.
part := partSet.GetPart(0)
part.Proof.Aunts[0][0] += byte(0x01)
added, err := partSet2.AddPart(part)
added, err := partSet2.AddPart(part, true)
if added || err == nil {
t.Errorf("Expected to fail adding a part with bad trail.")
}
@ -78,7 +78,7 @@ func TestWrongProof(t *testing.T) {
// Test adding a part with wrong bytes.
part = partSet.GetPart(1)
part.Bytes[0] += byte(0x01)
added, err = partSet2.AddPart(part)
added, err = partSet2.AddPart(part, true)
if added || err == nil {
t.Errorf("Expected to fail adding a part with bad bytes.")
}


Loading…
Cancel
Save