Skip to content

Commit 168cfe5

Browse files
authored
make proposal assembly time configurable (#3165)
## Summary This PR is doing the following: 1. Moves the proposal deadline computation outside of the agreement package and onto the node package. The agreement wasn't doing anything with the deadline anyway. 2. Make the proposal deadline be configured using a configuration parameter rather then a global hard-coded value in the config package. ## Test Plan Existing unit test provides sufficient coverage for this change.
1 parent 385afd5 commit 168cfe5

File tree

17 files changed

+135
-46
lines changed

17 files changed

+135
-46
lines changed

agreement/abstractions.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package agreement
1919
import (
2020
"context"
2121
"errors"
22-
"time"
2322

2423
"github.com/algorand/go-algorand/config"
2524
"github.com/algorand/go-algorand/crypto"
@@ -74,10 +73,7 @@ var ErrAssembleBlockRoundStale = errors.New("requested round for AssembleBlock i
7473
// Round.
7574
type BlockFactory interface {
7675
// AssembleBlock produces a new ValidatedBlock which is suitable for proposal
77-
// at a given Round. The time argument specifies a target deadline by
78-
// which the block should be produced. Specifically, the deadline can
79-
// cause the factory to add fewer transactions to the block in question
80-
// than might otherwise be possible.
76+
// at a given Round.
8177
//
8278
// AssembleBlock should produce a ValidatedBlock for which the corresponding
8379
// BlockValidator validates (i.e. for which BlockValidator.Validate
@@ -88,7 +84,7 @@ type BlockFactory interface {
8884
// produce a ValidatedBlock for the given round. If an insufficient number of
8985
// nodes on the network can assemble entries, the agreement protocol may
9086
// lose liveness.
91-
AssembleBlock(basics.Round, time.Time) (ValidatedBlock, error)
87+
AssembleBlock(basics.Round) (ValidatedBlock, error)
9288
}
9389

9490
// A Ledger represents the sequence of Entries agreed upon by the protocol.

agreement/agreementtest/simulate_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ type testBlockFactory struct {
9292
Owner int
9393
}
9494

95-
func (f testBlockFactory) AssembleBlock(r basics.Round, deadline time.Time) (agreement.ValidatedBlock, error) {
95+
func (f testBlockFactory) AssembleBlock(r basics.Round) (agreement.ValidatedBlock, error) {
9696
return testValidatedBlock{Inside: bookkeeping.Block{BlockHeader: bookkeeping.BlockHeader{Round: r}}}, nil
9797
}
9898

agreement/common_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"fmt"
2222
"math/rand"
2323
"testing"
24-
"time"
2524

2625
"github.com/algorand/go-deadlock"
2726
"github.com/stretchr/testify/require"
@@ -180,7 +179,7 @@ type testBlockFactory struct {
180179
Owner int
181180
}
182181

183-
func (f testBlockFactory) AssembleBlock(r basics.Round, deadline time.Time) (ValidatedBlock, error) {
182+
func (f testBlockFactory) AssembleBlock(r basics.Round) (ValidatedBlock, error) {
184183
return testValidatedBlock{Inside: bookkeeping.Block{BlockHeader: bookkeeping.BlockHeader{Round: r}}}, nil
185184
}
186185

@@ -422,7 +421,7 @@ type testAccountData struct {
422421
}
423422

424423
func makeProposalsTesting(accs testAccountData, round basics.Round, period period, factory BlockFactory, ledger Ledger) (ps []proposal, vs []vote) {
425-
ve, err := factory.AssembleBlock(round, time.Now().Add(time.Minute))
424+
ve, err := factory.AssembleBlock(round)
426425
if err != nil {
427426
logging.Base().Errorf("Could not generate a proposal for round %d: %v", round, err)
428427
return nil, nil
@@ -534,7 +533,7 @@ func (v *voteMakerHelper) MakeRandomProposalValue() *proposalValue {
534533

535534
func (v *voteMakerHelper) MakeRandomProposalPayload(t *testing.T, r round) (*proposal, *proposalValue) {
536535
f := testBlockFactory{Owner: 1}
537-
ve, err := f.AssembleBlock(r, time.Now().Add(time.Minute))
536+
ve, err := f.AssembleBlock(r)
538537
require.NoError(t, err)
539538

540539
var payload unauthenticatedProposal

agreement/fuzzer/ledger_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"context"
2121
"fmt"
2222
"math/rand"
23-
"time"
2423

2524
"github.com/algorand/go-algorand/agreement"
2625
"github.com/algorand/go-algorand/config"
@@ -109,7 +108,7 @@ type testBlockFactory struct {
109108
Owner int
110109
}
111110

112-
func (f testBlockFactory) AssembleBlock(r basics.Round, deadline time.Time) (agreement.ValidatedBlock, error) {
111+
func (f testBlockFactory) AssembleBlock(r basics.Round) (agreement.ValidatedBlock, error) {
113112
return testValidatedBlock{Inside: bookkeeping.Block{BlockHeader: bookkeeping.BlockHeader{Round: r}}}, nil
114113
}
115114

agreement/player_permutation_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package agreement
1919
import (
2020
"fmt"
2121
"testing"
22-
"time"
2322

2423
"github.com/stretchr/testify/require"
2524

@@ -32,7 +31,7 @@ import (
3231

3332
func makeRandomProposalPayload(r round) *proposal {
3433
f := testBlockFactory{Owner: 1}
35-
ve, _ := f.AssembleBlock(r, time.Time{})
34+
ve, _ := f.AssembleBlock(r)
3635

3736
var payload unauthenticatedProposal
3837
payload.Block = ve.Block()

agreement/proposalStore_test.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"os"
2121
"reflect"
2222
"testing"
23-
"time"
2423

2524
"github.com/stretchr/testify/require"
2625

@@ -65,7 +64,7 @@ func TestBlockAssemblerPipeline(t *testing.T) {
6564

6665
round := player.Round
6766
period := player.Period
68-
testBlockFactory, err := factory.AssembleBlock(player.Round, time.Now().Add(time.Minute))
67+
testBlockFactory, err := factory.AssembleBlock(player.Round)
6968
require.NoError(t, err, "Could not generate a proposal for round %d: %v", round, err)
7069

7170
accountIndex := 0
@@ -133,7 +132,7 @@ func TestBlockAssemblerBind(t *testing.T) {
133132

134133
player, _, accounts, factory, ledger := testSetup(0)
135134

136-
testBlockFactory, err := factory.AssembleBlock(player.Round, time.Now().Add(time.Minute))
135+
testBlockFactory, err := factory.AssembleBlock(player.Round)
137136
require.NoError(t, err, "Could not generate a proposal for round %d: %v", player.Round, err)
138137

139138
accountIndex := 0
@@ -201,7 +200,7 @@ func TestBlockAssemblerAuthenticator(t *testing.T) {
201200

202201
player, _, accounts, factory, ledger := testSetup(0)
203202

204-
testBlockFactory, err := factory.AssembleBlock(player.Round, time.Now().Add(time.Minute))
203+
testBlockFactory, err := factory.AssembleBlock(player.Round)
205204
require.NoError(t, err, "Could not generate a proposal for round %d: %v", player.Round, err)
206205
accountIndex := 0
207206
proposalPayload, _, _ := proposalForBlock(accounts.addresses[accountIndex], accounts.vrfs[accountIndex], testBlockFactory, player.Period, ledger)
@@ -267,7 +266,7 @@ func TestBlockAssemblerTrim(t *testing.T) {
267266

268267
player, _, accounts, factory, ledger := testSetup(0)
269268

270-
testBlockFactory, err := factory.AssembleBlock(player.Round, time.Now().Add(time.Minute))
269+
testBlockFactory, err := factory.AssembleBlock(player.Round)
271270
require.NoError(t, err, "Could not generate a proposal for round %d: %v", player.Round, err)
272271
accountIndex := 0
273272
proposalPayload, _, _ := proposalForBlock(accounts.addresses[accountIndex], accounts.vrfs[accountIndex], testBlockFactory, player.Period, ledger)
@@ -340,7 +339,7 @@ func TestProposalStoreT(t *testing.T) {
340339

341340
player, _, accounts, factory, ledger := testSetup(0)
342341

343-
testBlockFactory, err := factory.AssembleBlock(player.Round, time.Now().Add(time.Minute))
342+
testBlockFactory, err := factory.AssembleBlock(player.Round)
344343
require.NoError(t, err, "Could not generate a proposal for round %d: %v", player.Round, err)
345344
accountIndex := 0
346345
proposalPayload, proposalV, _ := proposalForBlock(accounts.addresses[accountIndex], accounts.vrfs[accountIndex], testBlockFactory, player.Period, ledger)
@@ -414,7 +413,7 @@ func TestProposalStoreUnderlying(t *testing.T) {
414413

415414
player, _, accounts, factory, ledger := testSetup(0)
416415

417-
testBlockFactory, err := factory.AssembleBlock(player.Round, time.Now().Add(time.Minute))
416+
testBlockFactory, err := factory.AssembleBlock(player.Round)
418417
require.NoError(t, err, "Could not generate a proposal for round %d: %v", player.Round, err)
419418
accountIndex := 0
420419
proposalPayload, proposalV, _ := proposalForBlock(accounts.addresses[accountIndex], accounts.vrfs[accountIndex], testBlockFactory, player.Period, ledger)
@@ -478,7 +477,7 @@ func TestProposalStoreHandle(t *testing.T) {
478477

479478
proposalVoteEventBatch, proposalPayloadEventBatch, _ := generateProposalEvents(t, player, accounts, factory, ledger)
480479

481-
testBlockFactory, err := factory.AssembleBlock(player.Round, time.Now().Add(time.Minute))
480+
testBlockFactory, err := factory.AssembleBlock(player.Round)
482481
require.NoError(t, err, "Could not generate a proposal for round %d: %v", player.Round, err)
483482
accountIndex := 0
484483
_, proposalV0, _ := proposalForBlock(accounts.addresses[accountIndex], accounts.vrfs[accountIndex], testBlockFactory, player.Period, ledger)
@@ -662,7 +661,7 @@ func TestProposalStoreGetPinnedValue(t *testing.T) {
662661

663662
// create proposal Store
664663
player, router, accounts, factory, ledger := testPlayerSetup()
665-
testBlockFactory, err := factory.AssembleBlock(player.Round, time.Now().Add(time.Minute))
664+
testBlockFactory, err := factory.AssembleBlock(player.Round)
666665
require.NoError(t, err, "Could not generate a proposal for round %d: %v", player.Round, err)
667666
accountIndex := 0
668667
// create a route handler for the proposal store

agreement/proposal_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"context"
2121
"os"
2222
"testing"
23-
"time"
2423

2524
"github.com/stretchr/testify/require"
2625

@@ -47,7 +46,7 @@ func testSetup(periodCount uint64) (player, rootRouter, testAccountData, testBlo
4746
}
4847

4948
func createProposalsTesting(accs testAccountData, round basics.Round, period period, factory BlockFactory, ledger Ledger) (ps []proposal, vs []vote) {
50-
ve, err := factory.AssembleBlock(round, time.Now().Add(time.Minute))
49+
ve, err := factory.AssembleBlock(round)
5150
if err != nil {
5251
logging.Base().Errorf("Could not generate a proposal for round %d: %v", round, err)
5352
return nil, nil
@@ -123,7 +122,7 @@ func TestProposalFunctions(t *testing.T) {
123122
player, _, accs, factory, ledger := testSetup(0)
124123
round := player.Round
125124
period := player.Period
126-
ve, err := factory.AssembleBlock(player.Round, time.Now().Add(time.Minute))
125+
ve, err := factory.AssembleBlock(player.Round)
127126
require.NoError(t, err, "Could not generate a proposal for round %d: %v", round, err)
128127

129128
validator := testBlockValidator{}
@@ -163,7 +162,7 @@ func TestProposalUnauthenticated(t *testing.T) {
163162

164163
round := player.Round
165164
period := player.Period
166-
testBlockFactory, err := factory.AssembleBlock(player.Round, time.Now().Add(time.Minute))
165+
testBlockFactory, err := factory.AssembleBlock(player.Round)
167166
require.NoError(t, err, "Could not generate a proposal for round %d: %v", round, err)
168167

169168
validator := testBlockValidator{}

agreement/pseudonode.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ import (
2020
"context"
2121
"fmt"
2222
"sync"
23-
"time"
2423

25-
"github.com/algorand/go-algorand/config"
2624
"github.com/algorand/go-algorand/data/account"
2725
"github.com/algorand/go-algorand/data/basics"
2826
"github.com/algorand/go-algorand/logging"
@@ -267,8 +265,7 @@ func (n asyncPseudonode) makePseudonodeVerifier(voteVerifier *AsyncVoteVerifier)
267265

268266
// makeProposals creates a slice of block proposals for the given round and period.
269267
func (n asyncPseudonode) makeProposals(round basics.Round, period period, accounts []account.Participation) ([]proposal, []unauthenticatedVote) {
270-
deadline := time.Now().Add(config.ProposalAssemblyTime)
271-
ve, err := n.factory.AssembleBlock(round, deadline)
268+
ve, err := n.factory.AssembleBlock(round)
272269
if err != nil {
273270
if err != ErrAssembleBlockRoundStale {
274271
n.log.Errorf("pseudonode.makeProposals: could not generate a proposal for round %d: %v", round, err)

config/config.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323
"os"
2424
"os/user"
2525
"path/filepath"
26-
"time"
2726

2827
"github.com/algorand/go-algorand/protocol"
2928
"github.com/algorand/go-algorand/util/codecs"
@@ -234,9 +233,6 @@ const (
234233
dnssecTelemetryAddr
235234
)
236235

237-
// ProposalAssemblyTime is the max amount of time to spend on generating a proposal block. This should eventually have it's own configurable value.
238-
const ProposalAssemblyTime time.Duration = 250 * time.Millisecond
239-
240236
const (
241237
catchupValidationModeCertificate = 1
242238
catchupValidationModePaysetHash = 2

config/localTemplate.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ type Local struct {
4141
// Version tracks the current version of the defaults so we can migrate old -> new
4242
// This is specifically important whenever we decide to change the default value
4343
// for an existing parameter. This field tag must be updated any time we add a new version.
44-
Version uint32 `version[0]:"0" version[1]:"1" version[2]:"2" version[3]:"3" version[4]:"4" version[5]:"5" version[6]:"6" version[7]:"7" version[8]:"8" version[9]:"9" version[10]:"10" version[11]:"11" version[12]:"12" version[13]:"13" version[14]:"14" version[15]:"15" version[16]:"16" version[17]:"17" version[18]:"18"`
44+
Version uint32 `version[0]:"0" version[1]:"1" version[2]:"2" version[3]:"3" version[4]:"4" version[5]:"5" version[6]:"6" version[7]:"7" version[8]:"8" version[9]:"9" version[10]:"10" version[11]:"11" version[12]:"12" version[13]:"13" version[14]:"14" version[15]:"15" version[16]:"16" version[17]:"17" version[18]:"18" version[19]:"19"`
4545

4646
// environmental (may be overridden)
4747
// When enabled, stores blocks indefinitally, otherwise, only the most recents blocks
@@ -417,6 +417,9 @@ type Local struct {
417417
// message before it can be used for calculating the data exchange rate. Setting this to zero
418418
// would use the default values. The threshold is defined in units of bytes.
419419
TransactionSyncSignificantMessageThreshold uint64 `version[17]:"0"`
420+
421+
// ProposalAssemblyTime is the max amount of time to spend on generating a proposal block.
422+
ProposalAssemblyTime time.Duration `version[19]:"250000000"`
420423
}
421424

422425
// DNSBootstrapArray returns an array of one or more DNS Bootstrap identifiers

0 commit comments

Comments
 (0)