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

[consensus] Continuously as Proposer in N rounds #4569

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
22 changes: 22 additions & 0 deletions action/protocol/rolldpos/epoch.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ type Protocol struct {
numSubEpochsDardanelles uint64
dardanellesHeight uint64
dardanellesOn bool
wakeHeight uint64
numProposalBatch uint64
numProposalBatchWake uint64
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete

}

// FindProtocol return a registered protocol from registry
Expand Down Expand Up @@ -74,6 +77,15 @@ func EnableDardanellesSubEpoch(height, numSubEpochs uint64) Option {
}
}

// EnableWakeProposalBatch will set the wake height and number of proposal batch wake
func EnableWakeProposalBatch(wakeHeight, numProposalBatchWake uint64) Option {
return func(p *Protocol) error {
p.wakeHeight = wakeHeight
p.numProposalBatchWake = numProposalBatchWake
return nil
}
}

// NewProtocol returns a new rolldpos protocol
func NewProtocol(numCandidateDelegates, numDelegates, numSubEpochs uint64, opts ...Option) *Protocol {
if numCandidateDelegates < numDelegates {
Expand All @@ -83,6 +95,7 @@ func NewProtocol(numCandidateDelegates, numDelegates, numSubEpochs uint64, opts
numCandidateDelegates: numCandidateDelegates,
numDelegates: numDelegates,
numSubEpochs: numSubEpochs,
numProposalBatch: 1,
}
for _, opt := range opts {
if err := opt(p); err != nil {
Expand Down Expand Up @@ -260,3 +273,12 @@ func (p *Protocol) ProductivityByEpoch(
produce, err := productivity(epochStartHeight, epochEndHeight)
return epochEndHeight - epochStartHeight + 1, produce, err
}

// ProposalBatchSizeByEpoch returns the number of proposal batch size in an epoch
func (p *Protocol) ProposalBatchSizeByEpoch(epochNum uint64) uint64 {
height := p.GetEpochHeight(epochNum)
if p.wakeHeight > 0 && height >= p.wakeHeight {
return p.numProposalBatchWake
}
return p.numProposalBatch
}
12 changes: 12 additions & 0 deletions blockchain/genesis/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func defaultConfig() Genesis {
NumCandidateDelegates: 36,
TimeBasedRotation: false,
MinBlocksForBlobRetention: 345600,
WakeNumProposalBatchSize: 5,
PacificBlockHeight: 432001,
AleutianBlockHeight: 864001,
BeringBlockHeight: 1512001,
Expand All @@ -79,6 +80,7 @@ func defaultConfig() Genesis {
TsunamiBlockHeight: 29275561,
UpernavikBlockHeight: 31174201,
VanuatuBlockHeight: 33730921,
WakeBlockHeight: math.MaxUint64,
ToBeEnabledBlockHeight: math.MaxUint64,
},
Account: Account{
Expand Down Expand Up @@ -186,6 +188,8 @@ type (
TimeBasedRotation bool `yaml:"timeBasedRotation"`
// MinBlocksForBlobRetention is the minimum number of blocks for blob retention
MinBlocksForBlobRetention uint64 `yaml:"minBlocksForBlobRetention"`
// WakeNumProposalBatchSize is the number of proposals in a batch
WakeNumProposalBatchSize uint64 `yaml:"numProposalBatchSize"`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ProposalBatchSize

// PacificBlockHeight is the start height of using the logic of Pacific version
// TODO: PacificBlockHeight is not added into protobuf definition for backward compatibility
PacificBlockHeight uint64 `yaml:"pacificHeight"`
Expand Down Expand Up @@ -276,6 +280,9 @@ type (
// 1. enable Cancun EVM
// 2. enable dynamic fee tx
VanuatuBlockHeight uint64 `yaml:"vanuatuHeight"`
// WakeBlockHeight is the start height to
// 1. enable 3s block interval
WakeBlockHeight uint64 `yaml:"wakeHeight"`
// ToBeEnabledBlockHeight is a fake height that acts as a gating factor for WIP features
// upon next release, change IsToBeEnabled() to IsNextHeight() for features to be released
ToBeEnabledBlockHeight uint64 `yaml:"toBeEnabledHeight"`
Expand Down Expand Up @@ -641,6 +648,11 @@ func (g *Blockchain) IsVanuatu(height uint64) bool {
return g.isPost(g.VanuatuBlockHeight, height)
}

// IsWake checks whether height is equal to or larger than wake height
func (g *Blockchain) IsWake(height uint64) bool {
return g.isPost(g.WakeBlockHeight, height)
}

// IsToBeEnabled checks whether height is equal to or larger than toBeEnabled height
func (g *Blockchain) IsToBeEnabled(height uint64) bool {
return g.isPost(g.ToBeEnabledBlockHeight, height)
Expand Down
1 change: 1 addition & 0 deletions chainservice/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,7 @@ func (builder *Builder) registerRollDPoSProtocol() error {
builder.cfg.Genesis.NumDelegates,
builder.cfg.Genesis.NumSubEpochs,
rolldpos.EnableDardanellesSubEpoch(builder.cfg.Genesis.DardanellesBlockHeight, builder.cfg.Genesis.DardanellesNumSubEpochs),
rolldpos.EnableWakeProposalBatch(builder.cfg.Genesis.WakeBlockHeight, builder.cfg.Genesis.WakeNumProposalBatchSize),
).Register(builder.cs.registry); err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions consensus/scheme/rolldpos/rolldpos_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func TestValidateBlockFooter(t *testing.T) {
blockHeight := uint64(8)
footer := &block.Footer{}
bc := mock_blockchain.NewMockBlockchain(ctrl)
bc.EXPECT().BlockFooterByHeight(blockHeight).Return(footer, nil).Times(5)
bc.EXPECT().BlockFooterByHeight(blockHeight).Return(footer, nil).AnyTimes()

sk1 := identityset.PrivateKey(1)
g := genesis.Default
Expand All @@ -216,7 +216,7 @@ func TestValidateBlockFooter(t *testing.T) {
Genesis: g,
SystemActive: true,
}
bc.EXPECT().Genesis().Return(g).Times(5)
bc.EXPECT().Genesis().Return(g).AnyTimes()
rp := rolldpos.NewProtocol(
g.NumCandidateDelegates,
g.NumDelegates,
Expand Down
3 changes: 2 additions & 1 deletion consensus/scheme/rolldpos/roundcalculator.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,8 @@ func (c *roundCalculator) calculateProposer(
err = errors.New("invalid proposer list")
return
}
idx := height
proposalBatch := c.rp.ProposalBatchSizeByEpoch(c.rp.GetEpochNum(height))
idx := height / proposalBatch
if c.timeBasedRotation {
idx += uint64(round)
}
Expand Down