Skip to content

Commit

Permalink
feat: add ChainProposedLength into the manifest (#788)
Browse files Browse the repository at this point in the history
* feat: add ChainProposedLength into the manifest

Signed-off-by: Jakub Sztandera <oss@kubuxu.com>

* Separate out max length and defualt length

Increase max length to 128 to line up with merke tree size

Signed-off-by: Jakub Sztandera <oss@kubuxu.com>

* fix manifest test

Signed-off-by: Jakub Sztandera <oss@kubuxu.com>

* Change ChainMaxLen to 128

Signed-off-by: Jakub Sztandera <oss@kubuxu.com>

---------

Signed-off-by: Jakub Sztandera <oss@kubuxu.com>
  • Loading branch information
Kubuxu authored Dec 12, 2024
1 parent b17b794 commit 1b17c6c
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 4 deletions.
3 changes: 2 additions & 1 deletion consensus_inputs.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ func (h *gpbftInputs) GetProposal(ctx context.Context, instance uint64) (_ *gpbf
return nil, nil, fmt.Errorf("computing powertable CID for base: %w", err)
}

suffix := make([]gpbft.TipSet, min(gpbft.ChainMaxLen-1, len(collectedChain))) // -1 because of base
suffixLen := min(gpbft.ChainMaxLen, h.manifest.Gpbft.ChainProposedLength) - 1 // -1 because of base
suffix := make([]gpbft.TipSet, min(suffixLen, len(collectedChain)))
for i := range suffix {
suffix[i].Key = collectedChain[i].Key()
suffix[i].Epoch = collectedChain[i].Epoch()
Expand Down
2 changes: 1 addition & 1 deletion f3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ func TestF3LateBootstrap(t *testing.T) {
env := newTestEnvironment(t).withNodes(2).start()

// Wait till we're "caught up".
bootstrapInstances := uint64(env.manifest.EC.Finality/(gpbft.ChainMaxLen-1)) + 1
bootstrapInstances := uint64(env.manifest.EC.Finality/(gpbft.ChainDefaultLen-1)) + 1
env.waitForInstanceNumber(bootstrapInstances, 30*time.Second, true)

// Wait until we've finalized a distant epoch. Once we do, our EC will forget the historical
Expand Down
4 changes: 3 additions & 1 deletion gpbft/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ const (
// CidMaxLen specifies the maximum length of a CID.
CidMaxLen = 38
// ChainMaxLen specifies the maximum length of a chain value.
ChainMaxLen = 100
ChainMaxLen = 128
// ChainDefaultLen specifies the default length of chain value.
ChainDefaultLen = 100
// TipsetKeyMaxLen specifies the maximum length of a tipset. The max size is
// chosen such that it allows ample space for an impossibly-unlikely number of
// blocks in a tipset, while maintaining a practical limit to prevent abuse.
Expand Down
2 changes: 1 addition & 1 deletion internal/powerstore/powerstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ func advanceF3(t *testing.T, m *manifest.Manifest, ps *powerstore.Store, cs *cer
basePt, err := cs.GetPowerTable(ctx, instance)
require.NoError(t, err)
for len(gpbftChain) > 1 {
count := min(len(gpbftChain), rand.IntN(epochsPerCert+1)+1, gpbft.ChainMaxLen)
count := min(len(gpbftChain), rand.IntN(epochsPerCert+1)+1, gpbft.ChainDefaultLen)
newChain := gpbftChain[:count]

nextPt := basePt
Expand Down
8 changes: 8 additions & 0 deletions manifest/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ var (
Delta: 6 * time.Second,
DeltaBackOffExponent: 2.0,
MaxLookaheadRounds: 5,
ChainProposedLength: gpbft.ChainDefaultLen,
RebroadcastBackoffBase: 6 * time.Second,
RebroadcastBackoffSpread: 0.1,
RebroadcastBackoffExponent: 1.3,
Expand Down Expand Up @@ -93,6 +94,8 @@ type GpbftConfig struct {
DeltaBackOffExponent float64
MaxLookaheadRounds uint64

ChainProposedLength int

RebroadcastBackoffBase time.Duration
RebroadcastBackoffExponent float64
RebroadcastBackoffSpread float64
Expand All @@ -107,6 +110,11 @@ func (g *GpbftConfig) Validate() error {
return fmt.Errorf("GPBFT backoff exponent must be at least 1.0, was %f", g.DeltaBackOffExponent)
}

if g.ChainProposedLength < 1 {
return fmt.Errorf("GPBFT proposed chain length cannot be less than 1")
}
// not checking against gpbft.ChainMaxLen, it is handled gracefully

if g.RebroadcastBackoffBase <= 0 {
return fmt.Errorf("GPBFT rebroadcast backoff base must be greater than 0, was %s",
g.RebroadcastBackoffBase)
Expand Down
1 change: 1 addition & 0 deletions manifest/manifest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ var base = manifest.Manifest{
Delta: 10,
DeltaBackOffExponent: 1.2,
MaxLookaheadRounds: 5,
ChainProposedLength: gpbft.ChainDefaultLen,
RebroadcastBackoffBase: 10,
RebroadcastBackoffExponent: 1.3,
RebroadcastBackoffMax: 30,
Expand Down

0 comments on commit 1b17c6c

Please sign in to comment.