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] - feat: hare preround proposal compaction #6129

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from 9 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
8 changes: 4 additions & 4 deletions blocks/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (

"github.com/spacemeshos/go-spacemesh/atxsdata"
"github.com/spacemeshos/go-spacemesh/common/types"
"github.com/spacemeshos/go-spacemesh/hare3"
"github.com/spacemeshos/go-spacemesh/hare3/eligibility"
"github.com/spacemeshos/go-spacemesh/hare4"
"github.com/spacemeshos/go-spacemesh/log"
"github.com/spacemeshos/go-spacemesh/proposals/store"
"github.com/spacemeshos/go-spacemesh/sql"
Expand All @@ -39,7 +39,7 @@ type Generator struct {
cert certifier
patrol layerPatrol

hareCh <-chan hare3.ConsensusOutput
hareCh <-chan hare4.ConsensusOutput
optimisticOutput map[types.LayerID]*proposalMetadata
}

Expand Down Expand Up @@ -76,7 +76,7 @@ func WithGeneratorLogger(logger *zap.Logger) GeneratorOpt {
}

// WithHareOutputChan sets the chan to listen to hare output.
func WithHareOutputChan(ch <-chan hare3.ConsensusOutput) GeneratorOpt {
func WithHareOutputChan(ch <-chan hare4.ConsensusOutput) GeneratorOpt {
return func(g *Generator) {
g.hareCh = ch
}
Expand Down Expand Up @@ -178,7 +178,7 @@ func (g *Generator) run(ctx context.Context) error {
}
}

func (g *Generator) processHareOutput(ctx context.Context, out hare3.ConsensusOutput) (*types.Block, error) {
func (g *Generator) processHareOutput(ctx context.Context, out hare4.ConsensusOutput) (*types.Block, error) {
var md *proposalMetadata
if len(out.Proposals) > 0 {
getMetadata := func() error {
Expand Down
46 changes: 23 additions & 23 deletions blocks/generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import (
"github.com/spacemeshos/go-spacemesh/blocks/mocks"
"github.com/spacemeshos/go-spacemesh/common/types"
"github.com/spacemeshos/go-spacemesh/genvm/sdk/wallet"
"github.com/spacemeshos/go-spacemesh/hare3"
"github.com/spacemeshos/go-spacemesh/hare3/eligibility"
"github.com/spacemeshos/go-spacemesh/hare4"
"github.com/spacemeshos/go-spacemesh/proposals/store"
"github.com/spacemeshos/go-spacemesh/signing"
"github.com/spacemeshos/go-spacemesh/sql"
Expand Down Expand Up @@ -56,13 +56,13 @@ type testGenerator struct {
mockFetch *smocks.MockProposalFetcher
mockCert *mocks.Mockcertifier
mockPatrol *mocks.MocklayerPatrol
hareCh chan hare3.ConsensusOutput
hareCh chan hare4.ConsensusOutput
}

func createTestGenerator(t *testing.T) *testGenerator {
types.SetLayersPerEpoch(3)
ctrl := gomock.NewController(t)
ch := make(chan hare3.ConsensusOutput, 100)
ch := make(chan hare4.ConsensusOutput, 100)
tg := &testGenerator{
mockMesh: mocks.NewMockmeshProvider(ctrl),
mockExec: mocks.NewMockexecutor(ctrl),
Expand Down Expand Up @@ -271,7 +271,7 @@ func genData(
store *store.Store,
lid types.LayerID,
optimistic bool,
) hare3.ConsensusOutput {
) hare4.ConsensusOutput {
numTXs := 1000
numProposals := 10
txIDs := createAndSaveTxs(t, numTXs, db)
Expand All @@ -283,7 +283,7 @@ func genData(
}
require.NoError(t, layers.SetMeshHash(db, lid.Sub(1), meshHash))
plist := createProposals(t, db, store, lid, meshHash, signers, activeSet, txIDs)
return hare3.ConsensusOutput{
return hare4.ConsensusOutput{
Layer: lid,
Proposals: types.ToProposalIDs(plist),
}
Expand Down Expand Up @@ -448,7 +448,7 @@ func Test_run(t *testing.T) {
})
tg.mockPatrol.EXPECT().CompleteHare(layerID)
tg.Start(context.Background())
tg.hareCh <- hare3.ConsensusOutput{Layer: layerID, Proposals: pids}
tg.hareCh <- hare4.ConsensusOutput{Layer: layerID, Proposals: pids}
require.Eventually(t, func() bool { return len(tg.hareCh) == 0 }, time.Second, 100*time.Millisecond)
tg.Stop()
})
Expand All @@ -464,7 +464,7 @@ func Test_processHareOutput_EmptyOutput(t *testing.T) {
tg.mockCert.EXPECT().CertifyIfEligible(gomock.Any(), layerID, types.EmptyBlockID)
tg.mockMesh.EXPECT().ProcessLayerPerHareOutput(gomock.Any(), layerID, types.EmptyBlockID, false)
tg.mockPatrol.EXPECT().CompleteHare(layerID)
tg.hareCh <- hare3.ConsensusOutput{Layer: layerID}
tg.hareCh <- hare4.ConsensusOutput{Layer: layerID}
require.Eventually(t, func() bool { return len(tg.hareCh) == 0 }, time.Second, 100*time.Millisecond)
tg.Stop()
}
Expand All @@ -480,7 +480,7 @@ func Test_run_FetchFailed(t *testing.T) {
return errors.New("unknown")
})
tg.mockPatrol.EXPECT().CompleteHare(layerID)
tg.hareCh <- hare3.ConsensusOutput{Layer: layerID, Proposals: pids}
tg.hareCh <- hare4.ConsensusOutput{Layer: layerID, Proposals: pids}
require.Eventually(t, func() bool { return len(tg.hareCh) == 0 }, time.Second, 100*time.Millisecond)
tg.Stop()
}
Expand All @@ -502,7 +502,7 @@ func Test_run_DiffHasFromConsensus(t *testing.T) {

tg.mockFetch.EXPECT().GetProposals(gomock.Any(), pids)
tg.mockPatrol.EXPECT().CompleteHare(layerID)
tg.hareCh <- hare3.ConsensusOutput{Layer: layerID, Proposals: pids}
tg.hareCh <- hare4.ConsensusOutput{Layer: layerID, Proposals: pids}
require.Eventually(t, func() bool { return len(tg.hareCh) == 0 }, time.Second, 100*time.Millisecond)
tg.Stop()
}
Expand Down Expand Up @@ -535,7 +535,7 @@ func Test_run_ExecuteFailed(t *testing.T) {
return nil, errors.New("unknown")
})
tg.mockPatrol.EXPECT().CompleteHare(layerID)
tg.hareCh <- hare3.ConsensusOutput{Layer: layerID, Proposals: pids}
tg.hareCh <- hare4.ConsensusOutput{Layer: layerID, Proposals: pids}
require.Eventually(t, func() bool { return len(tg.hareCh) == 0 }, time.Second, 100*time.Millisecond)
tg.Stop()
}
Expand All @@ -560,7 +560,7 @@ func Test_run_AddBlockFailed(t *testing.T) {
Return(block, nil)
tg.mockMesh.EXPECT().AddBlockWithTXs(gomock.Any(), gomock.Any()).Return(errors.New("unknown"))
tg.mockPatrol.EXPECT().CompleteHare(layerID)
tg.hareCh <- hare3.ConsensusOutput{Layer: layerID, Proposals: pids}
tg.hareCh <- hare4.ConsensusOutput{Layer: layerID, Proposals: pids}
require.Eventually(t, func() bool { return len(tg.hareCh) == 0 }, time.Second, 100*time.Millisecond)
tg.Stop()
}
Expand Down Expand Up @@ -588,7 +588,7 @@ func Test_run_RegisterCertFailureIgnored(t *testing.T) {
tg.mockCert.EXPECT().CertifyIfEligible(gomock.Any(), layerID, gomock.Any())
tg.mockMesh.EXPECT().ProcessLayerPerHareOutput(gomock.Any(), layerID, block.ID(), true)
tg.mockPatrol.EXPECT().CompleteHare(layerID)
tg.hareCh <- hare3.ConsensusOutput{Layer: layerID, Proposals: pids}
tg.hareCh <- hare4.ConsensusOutput{Layer: layerID, Proposals: pids}
require.Eventually(t, func() bool { return len(tg.hareCh) == 0 }, time.Second, 100*time.Millisecond)
tg.Stop()
}
Expand Down Expand Up @@ -616,7 +616,7 @@ func Test_run_CertifyFailureIgnored(t *testing.T) {
tg.mockCert.EXPECT().CertifyIfEligible(gomock.Any(), layerID, gomock.Any()).Return(errors.New("unknown"))
tg.mockMesh.EXPECT().ProcessLayerPerHareOutput(gomock.Any(), layerID, block.ID(), true)
tg.mockPatrol.EXPECT().CompleteHare(layerID)
tg.hareCh <- hare3.ConsensusOutput{Layer: layerID, Proposals: pids}
tg.hareCh <- hare4.ConsensusOutput{Layer: layerID, Proposals: pids}
require.Eventually(t, func() bool { return len(tg.hareCh) == 0 }, time.Second, 100*time.Millisecond)
tg.Stop()
}
Expand Down Expand Up @@ -646,7 +646,7 @@ func Test_run_ProcessLayerFailed(t *testing.T) {
ProcessLayerPerHareOutput(gomock.Any(), layerID, block.ID(), true).
Return(errors.New("unknown"))
tg.mockPatrol.EXPECT().CompleteHare(layerID)
tg.hareCh <- hare3.ConsensusOutput{Layer: layerID, Proposals: pids}
tg.hareCh <- hare4.ConsensusOutput{Layer: layerID, Proposals: pids}
require.Eventually(t, func() bool { return len(tg.hareCh) == 0 }, time.Second, 100*time.Millisecond)
tg.Stop()
}
Expand All @@ -673,7 +673,7 @@ func Test_processHareOutput_UnequalHeight(t *testing.T) {
activeSet := types.ToATXIDs(atxes)
pList := createProposals(t, tg.db, tg.proposals, layerID, types.Hash32{}, signers, activeSet, nil)
ctx := context.Background()
ho := hare3.ConsensusOutput{
ho := hare4.ConsensusOutput{
Layer: layerID,
Proposals: types.ToProposalIDs(pList),
}
Expand Down Expand Up @@ -730,7 +730,7 @@ func Test_processHareOutput_bad_state(t *testing.T) {
[]types.TransactionID{types.RandomTransactionID()},
1,
)
ho := hare3.ConsensusOutput{
ho := hare4.ConsensusOutput{
Layer: layerID,
Proposals: types.ToProposalIDs([]*types.Proposal{p}),
}
Expand Down Expand Up @@ -759,7 +759,7 @@ func Test_processHareOutput_bad_state(t *testing.T) {
1,
)
ctx := context.Background()
ho := hare3.ConsensusOutput{
ho := hare4.ConsensusOutput{
Layer: layerID,
Proposals: types.ToProposalIDs([]*types.Proposal{p}),
}
Expand All @@ -783,7 +783,7 @@ func Test_processHareOutput_EmptyProposals(t *testing.T) {
plist = append(plist, p)
}
ctx := context.Background()
ho := hare3.ConsensusOutput{
ho := hare4.ConsensusOutput{
Layer: lid,
Proposals: types.ToProposalIDs(plist),
}
Expand Down Expand Up @@ -832,7 +832,7 @@ func Test_processHareOutput_StableBlockID(t *testing.T) {
activeSet := types.ToATXIDs(atxes)
plist := createProposals(t, tg.db, tg.proposals, layerID, types.Hash32{}, signers, activeSet, txIDs)
ctx := context.Background()
ho1 := hare3.ConsensusOutput{
ho1 := hare4.ConsensusOutput{
Layer: layerID,
Proposals: types.ToProposalIDs(plist),
}
Expand All @@ -852,7 +852,7 @@ func Test_processHareOutput_StableBlockID(t *testing.T) {
ordered := plist[numProposals/2 : numProposals]
ordered = append(ordered, plist[0:numProposals/2]...)
require.NotEqual(t, plist, ordered)
ho2 := hare3.ConsensusOutput{
ho2 := hare4.ConsensusOutput{
Layer: layerID,
Proposals: types.ToProposalIDs(ordered),
}
Expand Down Expand Up @@ -881,7 +881,7 @@ func Test_processHareOutput_SameATX(t *testing.T) {
createProposal(t, tg.db, tg.proposals, activeSet, layerID, types.Hash32{}, atxID, signers[0], txIDs[0:500], 1),
createProposal(t, tg.db, tg.proposals, activeSet, layerID, types.Hash32{}, atxID, signers[0], txIDs[400:], 1),
}
ho := hare3.ConsensusOutput{
ho := hare4.ConsensusOutput{
Layer: layerID,
Proposals: types.ToProposalIDs(plist),
}
Expand All @@ -905,7 +905,7 @@ func Test_processHareOutput_EmptyATXID(t *testing.T) {
txIDs, 1,
)
plist = append(plist, p)
ho := hare3.ConsensusOutput{
ho := hare4.ConsensusOutput{
Layer: layerID,
Proposals: types.ToProposalIDs(plist),
}
Expand All @@ -928,7 +928,7 @@ func Test_processHareOutput_MultipleEligibilities(t *testing.T) {
createProposal(t, tg.db, tg.proposals, activeSet, layerID, types.Hash32{}, atxes[2].ID(), signers[2], ids, 5),
}
ctx := context.Background()
ho := hare3.ConsensusOutput{
ho := hare4.ConsensusOutput{
Layer: layerID,
Proposals: types.ToProposalIDs(plist),
}
Expand Down
12 changes: 11 additions & 1 deletion common/types/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,17 @@ type ProposalID Hash20
// EmptyProposalID is a canonical empty ProposalID.
var EmptyProposalID = ProposalID{}

type CompactProposalID [2]byte
type CompactProposalID [4]byte

// EncodeScale implements scale codec interface.
func (id *CompactProposalID) EncodeScale(e *scale.Encoder) (int, error) {
return scale.EncodeByteArray(e, id[:])
}

// DecodeScale implements scale codec interface.
func (id *CompactProposalID) DecodeScale(d *scale.Decoder) (int, error) {
return scale.DecodeByteArray(d, id[:])
}

// EncodeScale implements scale codec interface.
func (id *ProposalID) EncodeScale(e *scale.Encoder) (int, error) {
Expand Down
4 changes: 4 additions & 0 deletions common/types/testutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,16 @@ func RandomTransactionID() TransactionID {

// RandomBallot generates a Ballot with random content for testing.
func RandomBallot() *Ballot {
var vrf VrfSignature
_, _ = rand.Read(vrf[:])

return &Ballot{
InnerBallot: InnerBallot{
Layer: LayerID(10),
AtxID: RandomATXID(),
RefBallot: RandomBallotID(),
},
EligibilityProofs: []VotingEligibility{{Sig: vrf}},
Votes: Votes{
Base: RandomBallotID(),
Support: []Vote{{ID: RandomBlockID()}, {ID: RandomBlockID()}},
Expand Down
3 changes: 3 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
vm "github.com/spacemeshos/go-spacemesh/genvm"
"github.com/spacemeshos/go-spacemesh/hare3"
"github.com/spacemeshos/go-spacemesh/hare3/eligibility"
"github.com/spacemeshos/go-spacemesh/hare4"
"github.com/spacemeshos/go-spacemesh/miner"
"github.com/spacemeshos/go-spacemesh/p2p"
"github.com/spacemeshos/go-spacemesh/syncer"
Expand Down Expand Up @@ -54,6 +55,7 @@ type Config struct {
P2P p2p.Config `mapstructure:"p2p"`
API grpcserver.Config `mapstructure:"api"`
HARE3 hare3.Config `mapstructure:"hare3"`
HARE4 hare4.Config `mapstructure:"hare4"`
HareEligibility eligibility.Config `mapstructure:"hare-eligibility"`
Certificate blocks.CertConfig `mapstructure:"certificate"`
Beacon beacon.Config `mapstructure:"beacon"`
Expand Down Expand Up @@ -191,6 +193,7 @@ func DefaultConfig() Config {
P2P: p2p.DefaultConfig(),
API: grpcserver.DefaultConfig(),
HARE3: hare3.DefaultConfig(),
HARE4: hare4.DefaultConfig(), // DEFAULT HARE4 IS DISABLED
HareEligibility: eligibility.DefaultConfig(),
Beacon: beacon.DefaultConfig(),
TIME: timeConfig.DefaultConfig(),
Expand Down
7 changes: 7 additions & 0 deletions config/mainnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/spacemeshos/go-spacemesh/fetch"
"github.com/spacemeshos/go-spacemesh/hare3"
"github.com/spacemeshos/go-spacemesh/hare3/eligibility"
"github.com/spacemeshos/go-spacemesh/hare4"
"github.com/spacemeshos/go-spacemesh/miner"
"github.com/spacemeshos/go-spacemesh/p2p"
"github.com/spacemeshos/go-spacemesh/syncer"
Expand Down Expand Up @@ -61,6 +62,7 @@ func MainnetConfig() Config {
logging.TrtlLoggerLevel = zapcore.WarnLevel.String()
logging.AtxHandlerLevel = zapcore.WarnLevel.String()
logging.ProposalListenerLevel = zapcore.WarnLevel.String()
forkLayer := types.LayerID(111_111_111) // TODO THIS NEEDS A NUMBER
hare3conf := hare3.DefaultConfig()
hare3conf.Committee = 400
hare3conf.Enable = true
Expand All @@ -69,6 +71,10 @@ func MainnetConfig() Config {
Layer: 105_720, // July 15, 2024, 10:00:00 AM UTC
Size: 50,
}
hare3conf.DisableLayer = forkLayer

hare4conf := hare4.DefaultConfig()
hare4conf.Enable = false
return Config{
BaseConfig: BaseConfig{
DataDirParent: defaultDataDir,
Expand Down Expand Up @@ -137,6 +143,7 @@ func MainnetConfig() Config {
},
},
HARE3: hare3conf,
HARE4: hare4conf,
HareEligibility: eligibility.Config{
ConfidenceParam: 200,
},
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ require (
cloud.google.com/go/auth/oauth2adapt v0.2.2 // indirect
cloud.google.com/go/compute/metadata v0.3.0 // indirect
cloud.google.com/go/iam v1.1.8 // indirect
github.com/aead/siphash v1.0.1 // indirect
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 // indirect
github.com/anacrolix/chansync v0.3.0 // indirect
github.com/anacrolix/missinggo v1.2.1 // indirect
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ github.com/ALTree/bigfloat v0.2.0 h1:AwNzawrpFuw55/YDVlcPw0F0cmmXrmngBHhVrvdXPvM
github.com/ALTree/bigfloat v0.2.0/go.mod h1:+NaH2gLeY6RPBPPQf4aRotPPStg+eXc8f9ZaE4vRfD4=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/RoaringBitmap/roaring v0.4.7/go.mod h1:8khRDP4HmeXns4xIj9oGrKSz7XTQiJx2zgh7AcNke4w=
github.com/aead/siphash v1.0.1 h1:FwHfE/T45KPKYuuSAKyyvE+oPWcaQ+CUmFW0bPlM+kg=
github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII=
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 h1:s6gZFSlWYmbqAuRjVTiNNhvNRfY2Wxp9nhfyel4rklc=
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137/go.mod h1:OMCwj8VM1Kc9e19TLln2VL61YJF0x1XFtfdL4JdbSyE=
github.com/anacrolix/chansync v0.3.0 h1:lRu9tbeuw3wl+PhMu/r+JJCRu5ArFXIluOgdF0ao6/U=
Expand Down
4 changes: 2 additions & 2 deletions hare3/compat/weakcoin.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import (
"go.uber.org/zap"

"github.com/spacemeshos/go-spacemesh/common/types"
"github.com/spacemeshos/go-spacemesh/hare3"
"github.com/spacemeshos/go-spacemesh/hare4"
poszu marked this conversation as resolved.
Show resolved Hide resolved
)

type weakCoin interface {
Set(types.LayerID, bool) error
}

func ReportWeakcoin(ctx context.Context, logger *zap.Logger, from <-chan hare3.WeakCoinOutput, to weakCoin) {
func ReportWeakcoin(ctx context.Context, logger *zap.Logger, from <-chan hare4.WeakCoinOutput, to weakCoin) {
for {
select {
case <-ctx.Done():
Expand Down
Loading
Loading