Skip to content

Commit

Permalink
Fix nil ptr (#128)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlCutter authored Mar 7, 2024
1 parent b1b96f4 commit 8950d4e
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
6 changes: 5 additions & 1 deletion cmd/internal/distributor/distributor.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,11 @@ func (d *Distributor) Distribute(ctx context.Context, logID, witID string, nextR
return status.Errorf(codes.Internal, "failed to scan rows: %v", err)
}
allCheckpoints = append(allCheckpoints, cp)
witnesses = append(witnesses, d.ws[witID])
// If there is no known witness ID, this is probably due to an old witness
// having been removed from the config.
if w, ok := d.ws[witID]; ok {
witnesses = append(witnesses, w)
}
}

if err := rows.Err(); err != nil {
Expand Down
52 changes: 52 additions & 0 deletions cmd/internal/distributor/distributor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,58 @@ func TestFiltersUnknownSignatures(t *testing.T) {
}
}

func TestDisappearingWitness(t *testing.T) {
ws := map[string]note.Verifier{
aardvarkVKey: witAardvark.verifier,
badgerVKey: witBadger.verifier,
}
ls := map[string]config.LogInfo{
"FooLog": logFoo.LogInfo,
}

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
db, err := helper.create("TestDisappearingWitness")
if err != nil {
t.Fatalf("helper.create(): %v", err)
}

// Put a checkpoint in sigs from a known witness.
{
d, err := distributor.NewDistributor(ws, ls, db)
if err != nil {
t.Fatalf("NewDistributor(): %v", err)
}

writeCP := logFoo.checkpoint(16, "16", witAardvark.signer)
err = d.Distribute(ctx, "FooLog", "Aardvark", writeCP)
if err != nil {
t.Fatalf("Distribute(): %v", err)
}
}

// Now remove one of the witnesses; it was a bad aardvark.
ws = map[string]note.Verifier{
badgerVKey: witBadger.verifier,
chameleonVKey: witChameleon.verifier,
}

// Now recreate the distributor instance to represent re-deploying after the config update, and
// try to update the checkpoint with a new signature from another known witness.
{
d, err := distributor.NewDistributor(ws, ls, db)
if err != nil {
t.Fatalf("NewDistributor(): %v", err)
}

writeCP := logFoo.checkpoint(16, "16", witBadger.signer)
err = d.Distribute(ctx, "FooLog", "Badger", writeCP)
if err != nil {
t.Fatalf("Distribute(): %v", err)
}
}
}

func TestGetCheckpointN(t *testing.T) {
// The base case for this test is that 2 checkpoints have already been written:
// - aardvark, at tree size 16
Expand Down

0 comments on commit 8950d4e

Please sign in to comment.