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

ProposerVM Extend windows 1 - UTs Cleanup #2412

Merged
merged 33 commits into from
Dec 6, 2023
Merged

Conversation

abi87
Copy link
Contributor

@abi87 abi87 commented Dec 4, 2023

Why this should be merged

A few proposerVM unit tests are brittle.

  • They may assert the wrong error type
  • They make reference to core blocks Timestamps, while proposerVM production code never reference inner blocks timestamps post activation.
  • They may not properly set core blocks Height and Parent attributes, while proposerVM production code rely on them

This PR fixes these issues.

How this works

Just fixed the UTs

How this was tested

Manual inspection of each UT

@abi87 abi87 self-assigned this Dec 4, 2023
innerBlk := snowman.NewMockBlock(ctrl)
innerBlk.EXPECT().ID().Return(blkID).AnyTimes()
innerBlk.EXPECT().Height().Return(pChainHeight - 1).AnyTimes()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nit: maybe it's just me but having smaller blocks of code vs a single list of stuff makes code slighty less annoying. Happy to revert diff if this is not shared opinion

default:
return nil, errUnknownBlock
}
}

proVM.Set(proVM.Time().Add(proposer.MaxBuildDelay))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this time set is not really needed for the first block built on genesis.


// .. create child block ...
childCoreBlk := &snowman.TestBlock{
ParentV: prntCoreBlk.ID(),
BytesV: []byte{2},
TimestampV: prntCoreBlk.Timestamp(),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this the core block of a would be post fork block, its timestamp is not relevant to proposerVM. It's height and parent may be. So we better set up the right attributes

}
childSlb, err := block.Build(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

previous test version built a signed and then an unsigned block. There is no reason for that. I picked building two unsigned blocks just to simplify the test (that is really about parent checks)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ideally we'd like the same check carried out for signed blocks. We may add these UTs in a subsequent PR

require.NoError(err)
childProBlk.SignedBlock = childSlb
require.NoError(err)
{
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I scoped different tests cases this way, as we do in other parts of the codebase. Makes this diff more annoying but I think it improves overall readability. Also the more tightly scoped variables, the easier the maintanability I think

childProBlk.SignedBlock = childSlb

err = childProBlk.Verify(context.Background())
require.ErrorIs(err, errPChainHeightNotMonotonic)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

the test was not setup properly and here we were asserting the wrong error. Fixed

}

// child P-Chain height must not precede parent P-Chain height
childSlb, err := block.Build(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

once again a signed block and some unsigned blocks after. Not sure why. Moved to all unsigned blocks. To be revisited to extend UTs coverage over signed block.

Comment on lines +400 to +402
valState.GetMinimumHeightF = func(context.Context) (uint64, error) {
return pChainHeight / 50, nil
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this missing was the reason of the wrong error assertion below

BytesV: []byte{1},
ParentV: coreGenBlk.ID(),
HeightV: coreGenBlk.Height() + 1,
TimestampV: coreGenBlk.Timestamp(),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

these are inner blocks of would be post fork blocks. Their timestamp is irrelevant for proposerVM. Dropping it

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for taking this...caused a lot of confusion during the MaxVerify/BuildDelay change (at least for me).

@@ -210,6 +210,8 @@ func initTestProposerVM(
require.NoError(proVM.SetState(context.Background(), snow.NormalOp))
require.NoError(proVM.SetPreference(context.Background(), coreGenBlk.IDV))

proVM.Set(coreGenBlk.Timestamp())
Copy link
Contributor Author

@abi87 abi87 Dec 5, 2023

Choose a reason for hiding this comment

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

proposerVM clock should be not earlier that its genesis timestamp. We set them to be equal for simplicity here

@abi87 abi87 marked this pull request as ready for review December 5, 2023 08:53
default:
return nil, database.ErrNotFound
}
}

proVM.Set(proVM.Time().Add(proposer.MaxBuildDelay))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These are pre fork blocks, setting proposerVM clock is pointless. Dropped

}
coreVM.ParseBlockF = func(context.Context, []byte) (snowman.Block, error) {
return nil, errMarshallingFailed
}
slb, err := statelessblock.Build(
proVM.preferred,
innerBlk.Timestamp(),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

An example of the intertwining of innerBlk.Timestamp and proposerVM timestamp that we have in tests but not in production code. Dropped

@abi87 abi87 linked an issue Dec 5, 2023 that may be closed by this pull request
@abi87 abi87 changed the title Proposervm UTs cleanup ProposerVM Extend windows 0 - UTs Cleanup Dec 5, 2023
@abi87 abi87 changed the title ProposerVM Extend windows 0 - UTs Cleanup ProposerVM Extend windows 1 - UTs Cleanup Dec 5, 2023
Base automatically changed from proposervm_config to dev December 5, 2023 18:09
@StephenButtolph StephenButtolph added testing This primarily focuses on testing cleanup Code quality improvement labels Dec 6, 2023
@StephenButtolph StephenButtolph added this to the v1.10.18 milestone Dec 6, 2023
@StephenButtolph StephenButtolph added this pull request to the merge queue Dec 6, 2023
Merged via the queue into dev with commit ef2838d Dec 6, 2023
16 checks passed
@StephenButtolph StephenButtolph deleted the proposervm-uts-cleanup branch December 6, 2023 21:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cleanup Code quality improvement testing This primarily focuses on testing
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Extend proposerVMs windows
4 participants