Skip to content

Commit 4c4d935

Browse files
Share the prepare tipcut when building a reproposal (CON-468) (#4418)
## Summary - A reproposal keeps the prepare-certified tipcut and only moves the view forward, so `TimeoutQC.reproposal` no longer reads `Proposal.laneRanges` or copies them into a new map. - `Proposal.atView` returns that same tipcut at the next view, sharing the lane-range map. ## Test plan - [x] `go test ./sei-tendermint/autobahn/types/ -run 'TestProposalAtView|Reproposal'` - [ ] Confirm a reproposal still verifies against the prepare-certified tipcut (`TestProposalVerifyValidReproposal`) Made with [Cursor](https://cursor.com) Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 33a7e56 commit 4c4d935

3 files changed

Lines changed: 29 additions & 7 deletions

File tree

‎sei-tendermint/autobahn/types/proposal.go‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,16 @@ func (m *Proposal) Index() RoadIndex { return m.view.Index }
212212
// View of the proposal.
213213
func (m *Proposal) View() View { return m.view }
214214

215+
// atView returns this tipcut at view.
216+
func (m *Proposal) atView(view View) *Proposal {
217+
return &Proposal{
218+
view: view,
219+
timestamp: m.timestamp,
220+
laneRanges: m.laneRanges,
221+
globalRange: m.globalRange,
222+
}
223+
}
224+
215225
// Timestamp of the proposal.
216226
func (m *Proposal) Timestamp() time.Time { return m.timestamp }
217227

‎sei-tendermint/autobahn/types/proposal_test.go‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,24 @@ func TestProposalVerifyRejectsLaneQCHeaderHashMismatch(t *testing.T) {
675675
require.Error(t, err)
676676
}
677677

678+
func TestProposalAtView(t *testing.T) {
679+
rng := utils.TestRng()
680+
view := GenView(rng)
681+
timestamp := utils.GenTimestamp(rng)
682+
laneRanges := utils.GenSlice(rng, GenLaneRange)
683+
globalFirst := GlobalBlockNumber(rng.Uint64())
684+
p := newProposal(view, timestamp, laneRanges, globalFirst)
685+
686+
next := GenView(rng)
687+
got := p.atView(next)
688+
if err := utils.TestDiff(newProposal(next, timestamp, laneRanges, globalFirst), got); err != nil {
689+
t.Fatal(err)
690+
}
691+
if err := utils.TestDiff(newProposal(view, timestamp, laneRanges, globalFirst), p); err != nil {
692+
t.Fatal(err)
693+
}
694+
}
695+
678696
func TestProposalVerifyValidReproposal(t *testing.T) {
679697
rng := utils.TestRng()
680698
committee, keys := GenCommittee(rng, 4)

‎sei-tendermint/autobahn/types/timeout.go‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -215,13 +215,7 @@ func (m *TimeoutQC) reproposal() (*Proposal, bool) {
215215
if !ok {
216216
return nil, false
217217
}
218-
p := pQC.Proposal()
219-
// TODO(gprusak): this unnecessarily accesses internal state and does the copy. Fix it.
220-
var laneRanges []*LaneRange
221-
for _, l := range p.laneRanges {
222-
laneRanges = append(laneRanges, l)
223-
}
224-
return newProposal(m.View().Next(), p.Timestamp(), laneRanges, p.GlobalRange().First), true
218+
return pQC.Proposal().atView(m.View().Next()), true
225219
}
226220

227221
// TimeoutVoteConv is the protobuf converter for TimeoutVote.

0 commit comments

Comments
 (0)