From 922f720cf615061a46238ce42c6a54fe06280134 Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Mon, 21 Mar 2016 01:24:26 -0400 Subject: [PATCH] cswal_light logs own votes; fix tests --- consensus/replay_test.go | 5 +++-- consensus/state_test.go | 2 +- consensus/wal.go | 9 ++++++--- types/part_set.go | 2 +- types/part_set_test.go | 6 +++--- 5 files changed, 14 insertions(+), 10 deletions(-) diff --git a/consensus/replay_test.go b/consensus/replay_test.go index 40ec34ca8..044bb96cc 100644 --- a/consensus/replay_test.go +++ b/consensus/replay_test.go @@ -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) { diff --git a/consensus/state_test.go b/consensus/state_test.go index 277471267..eaac14dfe 100644 --- a/consensus/state_test.go +++ b/consensus/state_test.go @@ -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") } } diff --git a/consensus/wal.go b/consensus/wal.go index b5c79993d..5b4747a6f 100644 --- a/consensus/wal.go +++ b/consensus/wal.go @@ -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 diff --git a/types/part_set.go b/types/part_set.go index 146e23c43..c3e34cba3 100644 --- a/types/part_set.go +++ b/types/part_set.go @@ -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) diff --git a/types/part_set_test.go b/types/part_set_test.go index 4e74d7772..bbc3da9ed 100644 --- a/types/part_set_test.go +++ b/types/part_set_test.go @@ -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.") }