Skip to content

Commit f2f6d0a

Browse files
[vms/proposervm] Update Build Heuristic (#2348)
Co-authored-by: Alberto Benegiamo <alberto.benegiamo@gmail.com>
1 parent 459f8ba commit f2f6d0a

12 files changed

+345
-75
lines changed

vms/proposervm/batched_vm_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ func TestGetAncestorsPostForkOnly(t *testing.T) {
225225
// prepare build of next block
226226
require.NoError(builtBlk1.Verify(context.Background()))
227227
require.NoError(proRemoteVM.SetPreference(context.Background(), builtBlk1.ID()))
228-
proRemoteVM.Set(proRemoteVM.Time().Add(proposer.MaxDelay))
228+
proRemoteVM.Set(proRemoteVM.Time().Add(proposer.MaxBuildDelay))
229229

230230
coreBlk2 := &snowman.TestBlock{
231231
TestDecidable: choices.TestDecidable{
@@ -235,7 +235,7 @@ func TestGetAncestorsPostForkOnly(t *testing.T) {
235235
BytesV: []byte{2},
236236
ParentV: coreBlk1.ID(),
237237
HeightV: coreBlk1.Height() + 1,
238-
TimestampV: coreBlk1.Timestamp().Add(proposer.MaxDelay),
238+
TimestampV: coreBlk1.Timestamp().Add(proposer.MaxVerifyDelay),
239239
}
240240
coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) {
241241
return coreBlk2, nil
@@ -246,7 +246,7 @@ func TestGetAncestorsPostForkOnly(t *testing.T) {
246246
// prepare build of next block
247247
require.NoError(builtBlk2.Verify(context.Background()))
248248
require.NoError(proRemoteVM.SetPreference(context.Background(), builtBlk2.ID()))
249-
proRemoteVM.Set(proRemoteVM.Time().Add(proposer.MaxDelay))
249+
proRemoteVM.Set(proRemoteVM.Time().Add(proposer.MaxBuildDelay))
250250

251251
coreBlk3 := &snowman.TestBlock{
252252
TestDecidable: choices.TestDecidable{
@@ -431,7 +431,7 @@ func TestGetAncestorsAtSnomanPlusPlusFork(t *testing.T) {
431431
BytesV: []byte{3},
432432
ParentV: coreBlk2.ID(),
433433
HeightV: coreBlk2.Height() + 1,
434-
TimestampV: postForkTime.Add(proposer.MaxDelay),
434+
TimestampV: postForkTime.Add(proposer.MaxVerifyDelay),
435435
}
436436
coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) {
437437
return coreBlk3, nil
@@ -443,7 +443,7 @@ func TestGetAncestorsAtSnomanPlusPlusFork(t *testing.T) {
443443
// prepare build of next block
444444
require.NoError(builtBlk3.Verify(context.Background()))
445445
require.NoError(proRemoteVM.SetPreference(context.Background(), builtBlk3.ID()))
446-
proRemoteVM.Set(proRemoteVM.Time().Add(proposer.MaxDelay))
446+
proRemoteVM.Set(proRemoteVM.Time().Add(proposer.MaxBuildDelay))
447447

448448
coreBlk4 := &snowman.TestBlock{
449449
TestDecidable: choices.TestDecidable{
@@ -704,7 +704,7 @@ func TestBatchedParseBlockPostForkOnly(t *testing.T) {
704704
// prepare build of next block
705705
require.NoError(builtBlk1.Verify(context.Background()))
706706
require.NoError(proRemoteVM.SetPreference(context.Background(), builtBlk1.ID()))
707-
proRemoteVM.Set(proRemoteVM.Time().Add(proposer.MaxDelay))
707+
proRemoteVM.Set(proRemoteVM.Time().Add(proposer.MaxBuildDelay))
708708

709709
coreBlk2 := &snowman.TestBlock{
710710
TestDecidable: choices.TestDecidable{
@@ -714,7 +714,7 @@ func TestBatchedParseBlockPostForkOnly(t *testing.T) {
714714
BytesV: []byte{2},
715715
ParentV: coreBlk1.ID(),
716716
HeightV: coreBlk1.Height() + 1,
717-
TimestampV: coreBlk1.Timestamp().Add(proposer.MaxDelay),
717+
TimestampV: coreBlk1.Timestamp().Add(proposer.MaxVerifyDelay),
718718
}
719719
coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) {
720720
return coreBlk2, nil
@@ -725,7 +725,7 @@ func TestBatchedParseBlockPostForkOnly(t *testing.T) {
725725
// prepare build of next block
726726
require.NoError(builtBlk2.Verify(context.Background()))
727727
require.NoError(proRemoteVM.SetPreference(context.Background(), builtBlk2.ID()))
728-
proRemoteVM.Set(proRemoteVM.Time().Add(proposer.MaxDelay))
728+
proRemoteVM.Set(proRemoteVM.Time().Add(proposer.MaxBuildDelay))
729729

730730
coreBlk3 := &snowman.TestBlock{
731731
TestDecidable: choices.TestDecidable{
@@ -867,7 +867,7 @@ func TestBatchedParseBlockAtSnomanPlusPlusFork(t *testing.T) {
867867
BytesV: []byte{3},
868868
ParentV: coreBlk2.ID(),
869869
HeightV: coreBlk2.Height() + 1,
870-
TimestampV: postForkTime.Add(proposer.MaxDelay),
870+
TimestampV: postForkTime.Add(proposer.MaxVerifyDelay),
871871
}
872872
coreVM.BuildBlockF = func(context.Context) (snowman.Block, error) {
873873
return coreBlk3, nil
@@ -879,7 +879,7 @@ func TestBatchedParseBlockAtSnomanPlusPlusFork(t *testing.T) {
879879
// prepare build of next block
880880
require.NoError(builtBlk3.Verify(context.Background()))
881881
require.NoError(proRemoteVM.SetPreference(context.Background(), builtBlk3.ID()))
882-
proRemoteVM.Set(proRemoteVM.Time().Add(proposer.MaxDelay))
882+
proRemoteVM.Set(proRemoteVM.Time().Add(proposer.MaxBuildDelay))
883883

884884
coreBlk4 := &snowman.TestBlock{
885885
TestDecidable: choices.TestDecidable{

vms/proposervm/block.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ func (p *postForkCommonComponents) Verify(
144144

145145
childHeight := child.Height()
146146
proposerID := child.Proposer()
147-
minDelay, err := p.vm.Windower.Delay(ctx, childHeight, parentPChainHeight, proposerID)
147+
minDelay, err := p.vm.Windower.Delay(ctx, childHeight, parentPChainHeight, proposerID, proposer.MaxVerifyWindows)
148148
if err != nil {
149149
return err
150150
}
@@ -155,7 +155,7 @@ func (p *postForkCommonComponents) Verify(
155155
}
156156

157157
// Verify the signature of the node
158-
shouldHaveProposer := delay < proposer.MaxDelay
158+
shouldHaveProposer := delay < proposer.MaxVerifyDelay
159159
if err := child.SignedBlock.Verify(shouldHaveProposer, p.vm.ctx.ChainID); err != nil {
160160
return err
161161
}
@@ -203,10 +203,10 @@ func (p *postForkCommonComponents) buildChild(
203203
}
204204

205205
delay := newTimestamp.Sub(parentTimestamp)
206-
if delay < proposer.MaxDelay {
206+
if delay < proposer.MaxBuildDelay {
207207
parentHeight := p.innerBlk.Height()
208208
proposerID := p.vm.ctx.NodeID
209-
minDelay, err := p.vm.Windower.Delay(ctx, parentHeight+1, parentPChainHeight, proposerID)
209+
minDelay, err := p.vm.Windower.Delay(ctx, parentHeight+1, parentPChainHeight, proposerID, proposer.MaxBuildWindows)
210210
if err != nil {
211211
p.vm.ctx.Log.Error("unexpected build block failure",
212212
zap.String("reason", "failed to calculate required timestamp delay"),
@@ -249,7 +249,7 @@ func (p *postForkCommonComponents) buildChild(
249249

250250
// Build the child
251251
var statelessChild block.SignedBlock
252-
if delay >= proposer.MaxDelay {
252+
if delay >= proposer.MaxVerifyDelay {
253253
statelessChild, err = block.BuildUnsigned(
254254
parentID,
255255
newTimestamp,

0 commit comments

Comments
 (0)