Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - hare: use epoch first applied block for hare active set #5008

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion hare/eligibility/oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ func (o *Oracle) computeActiveSet(ctx context.Context, targetEpoch types.EpochID
return activeSet, nil
}

activeSet, err := miner.ActiveSetFromEpochFirstCertifiedBlock(o.cdb, targetEpoch)
activeSet, err := miner.ActiveSetFromEpochFirstBlock(o.cdb, targetEpoch)
if err != nil && !errors.Is(err, sql.ErrNotFound) {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions hare/eligibility/oracle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"github.com/spacemeshos/go-spacemesh/sql/atxs"
"github.com/spacemeshos/go-spacemesh/sql/ballots"
"github.com/spacemeshos/go-spacemesh/sql/blocks"
"github.com/spacemeshos/go-spacemesh/sql/certificates"
"github.com/spacemeshos/go-spacemesh/sql/layers"
"github.com/spacemeshos/go-spacemesh/system/mocks"
)

Expand Down Expand Up @@ -99,7 +99,7 @@ func createBlock(tb testing.TB, cdb *datastore.CachedDB, blts []*types.Ballot) {
}
block.Initialize()
require.NoError(tb, blocks.Add(cdb, block))
require.NoError(tb, certificates.Add(cdb, blts[0].Layer, &types.Certificate{BlockID: block.ID()}))
require.NoError(tb, layers.SetApplied(cdb, block.LayerIndex, block.ID()))
}

func createLayerData(tb testing.TB, cdb *datastore.CachedDB, lid types.LayerID, numMiners int) []types.NodeID {
Expand Down
9 changes: 0 additions & 9 deletions miner/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,9 @@ import (
"github.com/spacemeshos/go-spacemesh/sql"
"github.com/spacemeshos/go-spacemesh/sql/ballots"
"github.com/spacemeshos/go-spacemesh/sql/blocks"
"github.com/spacemeshos/go-spacemesh/sql/certificates"
"github.com/spacemeshos/go-spacemesh/sql/layers"
)

func ActiveSetFromEpochFirstCertifiedBlock(db sql.Executor, epoch types.EpochID) ([]types.ATXID, error) {
bid, err := certificates.FirstInEpoch(db, epoch)
if err != nil {
return nil, err
}
return activeSetFromBlock(db, bid)
}

func ActiveSetFromEpochFirstBlock(db sql.Executor, epoch types.EpochID) ([]types.ATXID, error) {
bid, err := layers.FirstAppliedInEpoch(db, epoch)
if err != nil {
Expand Down
36 changes: 7 additions & 29 deletions miner/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,40 +12,27 @@ import (
"github.com/spacemeshos/go-spacemesh/signing"
"github.com/spacemeshos/go-spacemesh/sql"
"github.com/spacemeshos/go-spacemesh/sql/blocks"
"github.com/spacemeshos/go-spacemesh/sql/certificates"
"github.com/spacemeshos/go-spacemesh/sql/layers"
)

func TestActiveSetFromEpochFirstBlock(t *testing.T) {
for _, tc := range []struct {
desc string
miner, hare bool
err error
desc string
err error
}{
{
desc: "actives for miner",
miner: true,
desc: "actives",
},
{
desc: "no actives for miner",
miner: true,
err: sql.ErrNotFound,
},
{
desc: "actives for hare",
hare: true,
},
{
desc: "no actives for hare",
hare: true,
desc: "no actives",
err: sql.ErrNotFound,
},
} {
t.Run(tc.desc, func(t *testing.T) {
epoch := types.EpochID(3)
cdb := datastore.NewCachedDB(sql.InMemory(), logtest.New(t))

got, err := ActiveSetFromEpochFirstCertifiedBlock(cdb, epoch)
got, err := ActiveSetFromEpochFirstBlock(cdb, epoch)
require.ErrorIs(t, err, sql.ErrNotFound)
require.Nil(t, got)

Expand All @@ -66,12 +53,7 @@ func TestActiveSetFromEpochFirstBlock(t *testing.T) {
block.Initialize()
require.NoError(t, blocks.Add(cdb, block))
if tc.err == nil {
if tc.miner {
require.NoError(t, layers.SetApplied(cdb, lid, block.ID()))
}
if tc.hare {
require.NoError(t, certificates.Add(cdb, lid, &types.Certificate{BlockID: block.ID()}))
}
require.NoError(t, layers.SetApplied(cdb, lid, block.ID()))
}
if i == 0 {
expected = all
Expand All @@ -83,11 +65,7 @@ func TestActiveSetFromEpochFirstBlock(t *testing.T) {
}
}

if tc.miner {
got, err = ActiveSetFromEpochFirstBlock(cdb, epoch)
} else if tc.hare {
got, err = ActiveSetFromEpochFirstCertifiedBlock(cdb, epoch)
}
got, err = ActiveSetFromEpochFirstBlock(cdb, epoch)
if tc.err != nil {
require.ErrorIs(t, err, tc.err)
} else {
Expand Down