Skip to content

Commit

Permalink
do not insist on cert to exist
Browse files Browse the repository at this point in the history
  • Loading branch information
countvonzero committed Sep 11, 2023
1 parent 8b371b1 commit 8b84a98
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion sql/certificates/certs.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func FirstInEpoch(db sql.Executor, epoch types.EpochID) (types.BlockID, error) {
rows int
)
if rows, err = db.Exec(`
select block from certificates where layer between ?1 and ?2 and valid = 1 and block != ?3 and cert is not null
select block from certificates where layer between ?1 and ?2 and valid = 1 and block != ?3
order by layer asc limit 1;`, func(stmt *sql.Statement) {
stmt.BindInt64(1, int64(epoch.FirstLayer()))
stmt.BindInt64(2, int64((epoch+1).FirstLayer()-1))
Expand Down
17 changes: 12 additions & 5 deletions sql/certificates/certs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,17 @@ func TestFirstInEpoch(t *testing.T) {
types.LayerID(2*layersPerEpoch - 1): {4}, // last layer of epoch 1
// epoch 2 has no hare output
types.LayerID(3 * layersPerEpoch): {5}, // first layer of epoch 3
// epoch 4 has hare output but no cert
types.LayerID(4 * layersPerEpoch): {6},
types.LayerID(5 * layersPerEpoch): {7},
}
for lid, bid := range lyrBlocks {
require.NoError(t, Add(db, lid, &types.Certificate{
BlockID: bid,
}))
require.NoError(t, SetHareOutput(db, lid, bid))
}
require.NoError(t, SetHareOutput(db, types.EpochID(4).FirstLayer(), types.BlockID{1, 2, 3}))
// epoch 4 has an invalid block
require.NoError(t, SetInvalid(db, types.EpochID(4).FirstLayer(), types.BlockID{6}))
// epoch 5 has a valid and invalid block each
require.NoError(t, SetHareOutput(db, types.EpochID(5).FirstLayer(), types.BlockID{1, 2, 3}))
require.NoError(t, SetInvalid(db, types.EpochID(5).FirstLayer(), types.BlockID{1, 2, 3}))

got, err := FirstInEpoch(db, types.EpochID(0))
require.NoError(t, err)
Expand All @@ -199,4 +202,8 @@ func TestFirstInEpoch(t *testing.T) {
got, err = FirstInEpoch(db, types.EpochID(4))
require.ErrorIs(t, err, sql.ErrNotFound)
require.Equal(t, types.EmptyBlockID, got)

got, err = FirstInEpoch(db, types.EpochID(5))
require.NoError(t, err)
require.Equal(t, types.BlockID{7}, got)
}

0 comments on commit 8b84a98

Please sign in to comment.