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

Version Block Support - testing infrastructure #223

Merged

Conversation

olegshmuelov
Copy link
Contributor

@olegshmuelov olegshmuelov commented May 8, 2023

This PR adds support for different beacon blocks in tests.
Currently, only Bellatrix is supported, but Capella will be added in a future PR.

  • To support multiple beacon block versions, we have added versioned functions with a "V" suffix to the existing beacon_node/ssv_msgs/runner functions. This allows us to keep the original functions while also supporting new versions.

  • We have also added versioned tests for proposer functions to ensure that there are no changes in roots, which use the versioned functions. Once this PR is approved and merged, we will adjust all proposer tests to use the versioned functions in a separate PR and delete the duplicates.

  • Once all proposer/randao tests have been aligned with the versioned functions, we can remove the "V" suffix and delete the deprecated functions. This will help us maintain a more efficient and streamlined codebase going forward.

@olegshmuelov olegshmuelov self-assigned this May 8, 2023
@GalRogozinski GalRogozinski requested a review from y0sher May 9, 2023 12:26
Duty: testingutils.TestingProposerDutyV(spec.DataVersionBellatrix),
Messages: []*types.SSVMessage{
testingutils.SSVMsgProposer(nil, testingutils.PostConsensusProposerMsgV(ks.Shares[1], 1, spec.DataVersionBellatrix)),
testingutils.SSVMsgProposer(nil, testingutils.PostConsensusWrongProposerMsgV(ks.Shares[1], 1, spec.DataVersionBellatrix)),
Copy link
Contributor

Choose a reason for hiding this comment

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

so we're testing only Bellatrix as part of this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, u can find the info in description

"github.com/bloxapp/ssv-spec/types"
)

var TestingBeaconBlockV = func(version spec.DataVersion) *spec.VersionedBeaconBlock {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand why you don't just write functions? instead of vars that hold functions..

Copy link
Contributor Author

Choose a reason for hiding this comment

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

keeping the current design
up to @GalRogozinski to decide if we want to break it

Copy link
Contributor

Choose a reason for hiding this comment

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

I think both of ways are fine...
So I don't see a reason to do a needless change

if @y0sher feels strongly about changing it we can discuss

Copy link
Contributor

Choose a reason for hiding this comment

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

if this is what existed before than yeah this isn't in the scope of this PR to change. generally I don't see why to write this way. in terms of IDE tooling like being able to see the function signature before using it's better to use the classic function structure than this.

"github.com/bloxapp/ssv-spec/types"
)

var TestingBeaconBlockV = func(version spec.DataVersion) *spec.VersionedBeaconBlock {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think both of ways are fine...
So I don't see a reason to do a needless change

if @y0sher feels strongly about changing it we can discuss

@@ -15,7 +15,7 @@ func InvalidMsgType() tests.SpecTest {
fullData, _ := obj.Encode()
root, _ := qbft.HashDataRoot(fullData)
msg := &qbft.Message{
MsgType: qbft.PrepareMsgType, //invalid, qbft.ProposeMsgType expected
MsgType: qbft.PrepareMsgType, //invalid, qbft.ProposeMsgType expected
Copy link
Contributor

Choose a reason for hiding this comment

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

This happened automatically right?

We need to setup a formatting standard for Go for all Blox's projects. Once everyone will have the same settings we will see less of those.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, automatically. agree

Comment on lines +130 to +133
CommitteeIndex: 3,
CommitteesAtSlot: 36,
CommitteeLength: 128,
ValidatorCommitteeIndex: 11,
Copy link
Contributor

Choose a reason for hiding this comment

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

Will those numbers make sense for future forks?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

should not affect future forks

Copy link
Contributor

Choose a reason for hiding this comment

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

If those fields are not used by our spec (and from my checks I believe there aren't) then I am not sure why we bother assigning them values.

I find adding code that looks somehow meaningful confusing.
I would delete this in another PR (because you copy-pasted existing logic, and we don't want to add changes here).

In the meanwhile add the following comment.

// ISSUE 233: We are initializing unused struct fields here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Comment on lines +152 to +155
CommitteeIndex: 3,
CommitteesAtSlot: 36,
CommitteeLength: 128,
ValidatorCommitteeIndex: 11,
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

Copy link
Contributor Author

Choose a reason for hiding this comment

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


switch version {
case spec.DataVersionBellatrix:
duty.Slot = TestingDutySlot2
Copy link
Contributor

Choose a reason for hiding this comment

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

How did you decide on this value?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

see new commits

@@ -52,7 +54,7 @@ var TestAggregatorConsensusDataByts, _ = TestAggregatorConsensusData.Encode()

var TestProposerConsensusData = &types.ConsensusData{
Duty: TestingProposerDuty,
Version: spec2.DataVersionBellatrix,
Version: spec.DataVersionBellatrix,
Copy link
Contributor

Choose a reason for hiding this comment

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

This whole file will be deleted and this is just temporary?

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 file should not be deleted, there is a logic besides proposals

"github.com/bloxapp/ssv-spec/types"
)

var TestProposerConsensusDataV = func(version spec.DataVersion) *types.ConsensusData {
Copy link
Contributor

Choose a reason for hiding this comment

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

All the functions in this file are currently being used in tests?
Meaning we can know they are ok since roots didn't change?

Copy link
Contributor Author

@olegshmuelov olegshmuelov May 10, 2023

Choose a reason for hiding this comment

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

All the functions in this file are currently being used in tests?

almost, there is a function PreConsensusRandaoNoMsgV that there is no usage for it in ssv_msgs as well

Meaning we can know they are ok since roots didn't change?

yes

return duty
}

var TestingProposerDutyNextEpochV = func(version spec.DataVersion) *types.Duty {
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

Messages: []*types.SSVMessage{
testingutils.SSVMsgProposer(nil, invalidateSlot(testingutils.PostConsensusProposerMsg(ks.Shares[1], 1))),
Copy link
Contributor

Choose a reason for hiding this comment

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

what happened to the impl of the old invalidate slot?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Comment on lines +32 to +46
msgF := func(obj *types.ConsensusData, id []byte) *qbft.SignedMessage {
// change slot
if len(obj.PreConsensusJustifications) > 0 {
obj.PreConsensusJustifications[0].Message.Slot = testingutils.TestingDutySlot2
}
return signedMsg(obj, id)
}

msgFV := func(obj *types.ConsensusData, id []byte) *qbft.SignedMessage {
// change slot
if len(obj.PreConsensusJustifications) > 0 {
obj.PreConsensusJustifications[0].Message.Slot = testingutils.TestingInvalidDutySlotV(obj.Version)
}
return signedMsg(obj, id)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

we still need both?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

theoretically not, but if we want to keep the same design for all the versioned examples in current PR, so yes

@GalRogozinski GalRogozinski requested a review from alonmuroch May 11, 2023 07:15
"github.com/bloxapp/ssv-spec/types"
)

var SSVDecidingMsgsV = func(consensusData *types.ConsensusData, ks *TestKeySet, role types.BeaconRole) []*types.SSVMessage {
Copy link
Contributor

Choose a reason for hiding this comment

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

why is this here?

Copy link
Contributor

Choose a reason for hiding this comment

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

You are right that the description said all the V suffixed tests should have the "V" removed out of them, since they become the default only option.
However, we noticed that doing so will create lots of changes that will have to be reviewed, slowing us down farther.

So I will change the description.

Copy link
Contributor

@y0sher y0sher left a comment

Choose a reason for hiding this comment

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

after reading the top msg, LGTM. approved.

@GalRogozinski
Copy link
Contributor

So @y0sher and @alonmuroch
What is happening right now is that there are "versioned" functions for proposer duty, and old non-versioned functions for other duties that are not going to be affected by Capella.

In essence, @y0sher is correct. Since this is an infra PR, and in theory future forks can change data for any duty, we should have only versioned code now.

However, let's take the following engineering principles into account:

  1. Keep PRs small as possible: more changes -> more cognitive load -> bigger chances of having something slip by
  2. Don't fix problems that don't exist: We shouldn't waste time preparing our code for changes that won't happen in the near future, and maybe won't come up in the far future.

So I am not sure if those changes should happen in this PR, or that they are even a priority.

@liorrutenberg liorrutenberg merged commit b8be134 into ssvlabs:main May 11, 2023
@olegshmuelov olegshmuelov deleted the version-block-support-testing-infra branch May 11, 2023 15:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants