From 382e5c186ad8a41719358db86bddd4d64e7b8574 Mon Sep 17 00:00:00 2001 From: rupam-04 Date: Thu, 4 Jul 2024 16:48:37 +0530 Subject: [PATCH 01/13] feat: implement ``is_better_update`` for light client --- beacon-chain/rpc/eth/light-client/helpers.go | 76 ++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/beacon-chain/rpc/eth/light-client/helpers.go b/beacon-chain/rpc/eth/light-client/helpers.go index cde39540b66e..254d11543e35 100644 --- a/beacon-chain/rpc/eth/light-client/helpers.go +++ b/beacon-chain/rpc/eth/light-client/helpers.go @@ -13,11 +13,16 @@ import ( "github.com/prysmaticlabs/prysm/v5/config/params" "github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces" v1 "github.com/prysmaticlabs/prysm/v5/proto/eth/v1" + ethpbv2 "github.com/prysmaticlabs/prysm/v5/proto/eth/v2" v2 "github.com/prysmaticlabs/prysm/v5/proto/eth/v2" "github.com/prysmaticlabs/prysm/v5/proto/migration" "github.com/prysmaticlabs/prysm/v5/time/slots" ) +const ( + finalityBranchNumOfLeaves = 6 +) + // createLightClientBootstrap - implements https://github.com/ethereum/consensus-specs/blob/3d235740e5f1e641d3b160c8688f26e7dc5a1894/specs/altair/light-client/full-node.md#create_light_client_bootstrap // def create_light_client_bootstrap(state: BeaconState) -> LightClientBootstrap: // @@ -311,3 +316,74 @@ func newLightClientUpdateToJSON(input *v2.LightClientUpdate) *structs.LightClien SignatureSlot: strconv.FormatUint(uint64(input.SignatureSlot), 10), } } + +func isSyncCommitteeUpdate(update *ethpbv2.LightClientUpdate) bool { + nextSyncCommitteeBranch := make([][]byte, fieldparams.NextSyncCommitteeBranchDepth) + return update.NextSyncCommitteeBranch != nextSyncCommitteeBranch +} + +func isFinalityUpdate(update *ethpbv2.LightClientUpdate) bool { + finalityBranch := make([][]byte, finalityBranchNumOfLeaves) + return update.FinalityBranch != finalityBranch +} + +func isBetterUpdate(newUpdate, oldUpdate *ethpbv2.LightClientUpdate) bool { + maxActiveParticipants := newUpdate.SyncAggregate.SyncCommitteeBits.Len() + newNumActiveParticipants := uint64(0) + for i := uint64(0); i < maxActiveParticipants; i++ { + if newUpdate.SyncAggregate.SyncCommitteeBits.BitAt(i) { + newNumActiveParticipants += 1 + } + } + oldNumActiveParticipants := uint64(0) + for i := uint64(0); i < oldUpdate.SyncAggregate.SyncCommitteeBits.Len(); i++ { + if oldUpdate.SyncAggregate.SyncCommitteeBits.BitAt(i) { + oldNumActiveParticipants += 1 + } + } + newHasSupermajority := newNumActiveParticipants*3 >= maxActiveParticipants*2 + oldHasSupermajority := oldNumActiveParticipants*3 >= maxActiveParticipants*2 + + if newHasSupermajority != oldHasSupermajority { + return newHasSupermajority + } + if !newHasSupermajority && newNumActiveParticipants != oldNumActiveParticipants { + return newNumActiveParticipants > oldNumActiveParticipants + } + + // Compare presence of relevant sync committee + newHasRelevantSyncCommittee := isSyncCommitteeUpdate(newUpdate) && (slots.ToEpoch(newUpdate.AttestedHeader.Slot) == slots.ToEpoch(newUpdate.SignatureSlot)) + oldHasRelevantSyncCommittee := isSyncCommitteeUpdate(oldUpdate) && (slots.ToEpoch(oldUpdate.AttestedHeader.Slot) == slots.ToEpoch(oldUpdate.SignatureSlot)) + + if newHasRelevantSyncCommittee != oldHasRelevantSyncCommittee { + return newHasRelevantSyncCommittee + } + + // Compare indication of any finality + newHasFinality := isFinalityUpdate(newUpdate) + oldHasFinality := isFinalityUpdate(oldUpdate) + if newHasFinality != oldHasFinality { + return newHasFinality + } + + // Compare sync committee finality + if newHasFinality { + newHasSyncCommitteeFinality := slots.ToEpoch(newUpdate.FinalizedHeader.Slot) == slots.ToEpoch(newUpdate.AttestedHeader.Slot) + oldHasSyncCommitteeFinality := slots.ToEpoch(oldUpdate.FinalizedHeader.Slot) == slots.ToEpoch(oldUpdate.AttestedHeader.Slot) + + if newHasSyncCommitteeFinality != oldHasSyncCommitteeFinality { + return newHasSyncCommitteeFinality + } + } + + // Tiebreaker 1: Sync committee participation beyond supermajority + if newNumActiveParticipants != oldNumActiveParticipants { + return newNumActiveParticipants > oldNumActiveParticipants + } + + // Tiebreaker 2: Prefer older data (fewer changes to best) + if newUpdate.AttestedHeader.Slot != oldUpdate.AttestedHeader.Slot { + return newUpdate.AttestedHeader.Slot < oldUpdate.AttestedHeader.Slot + } + return newUpdate.SignatureSlot < oldUpdate.SignatureSlot +} From 1829feb1bb8c0f121708cad98a800edca3523eb3 Mon Sep 17 00:00:00 2001 From: rupam-04 Date: Fri, 5 Jul 2024 02:44:56 +0530 Subject: [PATCH 02/13] replace ``!=`` with ``!reflect.DeepEqual`` --- beacon-chain/rpc/eth/light-client/helpers.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/beacon-chain/rpc/eth/light-client/helpers.go b/beacon-chain/rpc/eth/light-client/helpers.go index 254d11543e35..7aef38538d69 100644 --- a/beacon-chain/rpc/eth/light-client/helpers.go +++ b/beacon-chain/rpc/eth/light-client/helpers.go @@ -3,6 +3,7 @@ package lightclient import ( "context" "fmt" + "reflect" "strconv" "github.com/ethereum/go-ethereum/common/hexutil" @@ -319,12 +320,12 @@ func newLightClientUpdateToJSON(input *v2.LightClientUpdate) *structs.LightClien func isSyncCommitteeUpdate(update *ethpbv2.LightClientUpdate) bool { nextSyncCommitteeBranch := make([][]byte, fieldparams.NextSyncCommitteeBranchDepth) - return update.NextSyncCommitteeBranch != nextSyncCommitteeBranch + return !reflect.DeepEqual(update.NextSyncCommitteeBranch, nextSyncCommitteeBranch) } func isFinalityUpdate(update *ethpbv2.LightClientUpdate) bool { finalityBranch := make([][]byte, finalityBranchNumOfLeaves) - return update.FinalityBranch != finalityBranch + return !reflect.DeepEqual(update.FinalityBranch, finalityBranch) } func isBetterUpdate(newUpdate, oldUpdate *ethpbv2.LightClientUpdate) bool { From 59ce8d96b5a5ac9bedd47f20e858c9ab764d7600 Mon Sep 17 00:00:00 2001 From: rupam-04 Date: Sat, 6 Jul 2024 17:45:43 +0530 Subject: [PATCH 03/13] chore: import constant instead of redeclaring and some minor fixes --- beacon-chain/blockchain/lightclient.go | 6 ++--- beacon-chain/blockchain/lightclient_test.go | 2 +- beacon-chain/rpc/eth/light-client/helpers.go | 24 ++++---------------- 3 files changed, 9 insertions(+), 23 deletions(-) diff --git a/beacon-chain/blockchain/lightclient.go b/beacon-chain/blockchain/lightclient.go index 4a6890659510..ade4258cbb12 100644 --- a/beacon-chain/blockchain/lightclient.go +++ b/beacon-chain/blockchain/lightclient.go @@ -16,7 +16,7 @@ import ( ) const ( - finalityBranchNumOfLeaves = 6 + FinalityBranchNumOfLeaves = 6 ) // CreateLightClientFinalityUpdate - implements https://github.com/ethereum/consensus-specs/blob/3d235740e5f1e641d3b160c8688f26e7dc5a1894/specs/altair/light-client/full-node.md#create_light_client_finality_update @@ -215,8 +215,8 @@ func NewLightClientFinalityUpdateFromBeaconState( BodyRoot: make([]byte, 32), } - finalityBranch = make([][]byte, finalityBranchNumOfLeaves) - for i := 0; i < finalityBranchNumOfLeaves; i++ { + finalityBranch = make([][]byte, FinalityBranchNumOfLeaves) + for i := 0; i < FinalityBranchNumOfLeaves; i++ { finalityBranch[i] = make([]byte, 32) } } diff --git a/beacon-chain/blockchain/lightclient_test.go b/beacon-chain/blockchain/lightclient_test.go index a635558a0d87..41a3a7cfacdb 100644 --- a/beacon-chain/blockchain/lightclient_test.go +++ b/beacon-chain/blockchain/lightclient_test.go @@ -153,7 +153,7 @@ func TestLightClient_NewLightClientFinalityUpdateFromBeaconState(t *testing.T) { require.DeepSSZEqual(t, zeroHash, update.FinalizedHeader.ParentRoot, "Finalized header parent root is not zero") require.DeepSSZEqual(t, zeroHash, update.FinalizedHeader.StateRoot, "Finalized header state root is not zero") require.DeepSSZEqual(t, zeroHash, update.FinalizedHeader.BodyRoot, "Finalized header body root is not zero") - require.Equal(t, finalityBranchNumOfLeaves, len(update.FinalityBranch), "Invalid finality branch leaves") + require.Equal(t, FinalityBranchNumOfLeaves, len(update.FinalityBranch), "Invalid finality branch leaves") for _, leaf := range update.FinalityBranch { require.DeepSSZEqual(t, zeroHash, leaf, "Leaf is not zero") } diff --git a/beacon-chain/rpc/eth/light-client/helpers.go b/beacon-chain/rpc/eth/light-client/helpers.go index 7aef38538d69..f942a4e07c2d 100644 --- a/beacon-chain/rpc/eth/light-client/helpers.go +++ b/beacon-chain/rpc/eth/light-client/helpers.go @@ -20,10 +20,6 @@ import ( "github.com/prysmaticlabs/prysm/v5/time/slots" ) -const ( - finalityBranchNumOfLeaves = 6 -) - // createLightClientBootstrap - implements https://github.com/ethereum/consensus-specs/blob/3d235740e5f1e641d3b160c8688f26e7dc5a1894/specs/altair/light-client/full-node.md#create_light_client_bootstrap // def create_light_client_bootstrap(state: BeaconState) -> LightClientBootstrap: // @@ -324,24 +320,14 @@ func isSyncCommitteeUpdate(update *ethpbv2.LightClientUpdate) bool { } func isFinalityUpdate(update *ethpbv2.LightClientUpdate) bool { - finalityBranch := make([][]byte, finalityBranchNumOfLeaves) + finalityBranch := make([][]byte, blockchain.FinalityBranchNumOfLeaves) return !reflect.DeepEqual(update.FinalityBranch, finalityBranch) } func isBetterUpdate(newUpdate, oldUpdate *ethpbv2.LightClientUpdate) bool { maxActiveParticipants := newUpdate.SyncAggregate.SyncCommitteeBits.Len() - newNumActiveParticipants := uint64(0) - for i := uint64(0); i < maxActiveParticipants; i++ { - if newUpdate.SyncAggregate.SyncCommitteeBits.BitAt(i) { - newNumActiveParticipants += 1 - } - } - oldNumActiveParticipants := uint64(0) - for i := uint64(0); i < oldUpdate.SyncAggregate.SyncCommitteeBits.Len(); i++ { - if oldUpdate.SyncAggregate.SyncCommitteeBits.BitAt(i) { - oldNumActiveParticipants += 1 - } - } + newNumActiveParticipants := newUpdate.SyncAggregate.SyncCommitteeBits.Count() + oldNumActiveParticipants := oldUpdate.SyncAggregate.SyncCommitteeBits.Count() newHasSupermajority := newNumActiveParticipants*3 >= maxActiveParticipants*2 oldHasSupermajority := oldNumActiveParticipants*3 >= maxActiveParticipants*2 @@ -353,8 +339,8 @@ func isBetterUpdate(newUpdate, oldUpdate *ethpbv2.LightClientUpdate) bool { } // Compare presence of relevant sync committee - newHasRelevantSyncCommittee := isSyncCommitteeUpdate(newUpdate) && (slots.ToEpoch(newUpdate.AttestedHeader.Slot) == slots.ToEpoch(newUpdate.SignatureSlot)) - oldHasRelevantSyncCommittee := isSyncCommitteeUpdate(oldUpdate) && (slots.ToEpoch(oldUpdate.AttestedHeader.Slot) == slots.ToEpoch(oldUpdate.SignatureSlot)) + newHasRelevantSyncCommittee := isSyncCommitteeUpdate(newUpdate) && (slots.SyncCommitteePeriod(slots.ToEpoch(newUpdate.AttestedHeader.Slot)) == slots.SyncCommitteePeriod(slots.ToEpoch(newUpdate.SignatureSlot))) + oldHasRelevantSyncCommittee := isSyncCommitteeUpdate(oldUpdate) && (slots.SyncCommitteePeriod(slots.ToEpoch(oldUpdate.AttestedHeader.Slot)) == slots.SyncCommitteePeriod(slots.ToEpoch(oldUpdate.SignatureSlot))) if newHasRelevantSyncCommittee != oldHasRelevantSyncCommittee { return newHasRelevantSyncCommittee From b71f03c3209ddbb6bd0307f2c1c93523f91a0fa2 Mon Sep 17 00:00:00 2001 From: rupam-04 Date: Sun, 14 Jul 2024 01:54:00 +0530 Subject: [PATCH 04/13] feat: add test for ``newHasSupermajority != oldHasSupermajority`` --- .../rpc/eth/light-client/helpers_test.go | 279 ++++++++++++++++++ 1 file changed, 279 insertions(+) create mode 100644 beacon-chain/rpc/eth/light-client/helpers_test.go diff --git a/beacon-chain/rpc/eth/light-client/helpers_test.go b/beacon-chain/rpc/eth/light-client/helpers_test.go new file mode 100644 index 000000000000..97dcb8f73434 --- /dev/null +++ b/beacon-chain/rpc/eth/light-client/helpers_test.go @@ -0,0 +1,279 @@ +package lightclient + +import ( + "context" + "testing" + + "github.com/prysmaticlabs/prysm/v5/beacon-chain/blockchain" + "github.com/prysmaticlabs/prysm/v5/beacon-chain/state" + "github.com/prysmaticlabs/prysm/v5/config/params" + "github.com/prysmaticlabs/prysm/v5/consensus-types/blocks" + "github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces" + "github.com/prysmaticlabs/prysm/v5/consensus-types/primitives" + ethpbv2 "github.com/prysmaticlabs/prysm/v5/proto/eth/v2" + ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" + "github.com/prysmaticlabs/prysm/v5/testing/require" + "github.com/prysmaticlabs/prysm/v5/testing/util" +) + +type testlc struct { + t *testing.T + ctx context.Context + state state.BeaconState + block interfaces.ReadOnlySignedBeaconBlock + attestedState state.BeaconState + attestedHeader *ethpb.BeaconBlockHeader +} + +func newTestLc(t *testing.T) *testlc { + return &testlc{t: t} +} + +func (l *testlc) setupTest_SyncCommitteeBits_Equals_Zero() *testlc { + ctx := context.Background() + + slot := primitives.Slot(params.BeaconConfig().AltairForkEpoch * primitives.Epoch(params.BeaconConfig().SlotsPerEpoch)).Add(1) + + attestedState, err := util.NewBeaconStateCapella() + require.NoError(l.t, err) + err = attestedState.SetSlot(slot) + require.NoError(l.t, err) + + parent := util.NewBeaconBlockCapella() + parent.Block.Slot = slot + + signedParent, err := blocks.NewSignedBeaconBlock(parent) + require.NoError(l.t, err) + + parentHeader, err := signedParent.Header() + require.NoError(l.t, err) + attestedHeader := parentHeader.Header + + err = attestedState.SetLatestBlockHeader(attestedHeader) + require.NoError(l.t, err) + attestedStateRoot, err := attestedState.HashTreeRoot(ctx) + require.NoError(l.t, err) + + // get a new signed block so the root is updated with the new state root + parent.Block.StateRoot = attestedStateRoot[:] + signedParent, err = blocks.NewSignedBeaconBlock(parent) + require.NoError(l.t, err) + + state, err := util.NewBeaconStateCapella() + require.NoError(l.t, err) + err = state.SetSlot(slot) + require.NoError(l.t, err) + + parentRoot, err := signedParent.Block().HashTreeRoot() + require.NoError(l.t, err) + + block := util.NewBeaconBlockCapella() + block.Block.Slot = slot + block.Block.ParentRoot = parentRoot[:] + + signedBlock, err := blocks.NewSignedBeaconBlock(block) + require.NoError(l.t, err) + + h, err := signedBlock.Header() + require.NoError(l.t, err) + + err = state.SetLatestBlockHeader(h.Header) + require.NoError(l.t, err) + stateRoot, err := state.HashTreeRoot(ctx) + require.NoError(l.t, err) + + // get a new signed block so the root is updated with the new state root + block.Block.StateRoot = stateRoot[:] + signedBlock, err = blocks.NewSignedBeaconBlock(block) + require.NoError(l.t, err) + + l.state = state + l.attestedState = attestedState + l.attestedHeader = attestedHeader + l.block = signedBlock + l.ctx = ctx + + return l +} + +func (l *testlc) setupTest_SyncCommitteeBits_Equals_MoreThanTwoThirds() *testlc { + ctx := context.Background() + + slot := primitives.Slot(params.BeaconConfig().AltairForkEpoch * primitives.Epoch(params.BeaconConfig().SlotsPerEpoch)).Add(1) + + attestedState, err := util.NewBeaconStateCapella() + require.NoError(l.t, err) + err = attestedState.SetSlot(slot) + require.NoError(l.t, err) + + parent := util.NewBeaconBlockCapella() + parent.Block.Slot = slot + + signedParent, err := blocks.NewSignedBeaconBlock(parent) + require.NoError(l.t, err) + + parentHeader, err := signedParent.Header() + require.NoError(l.t, err) + attestedHeader := parentHeader.Header + + err = attestedState.SetLatestBlockHeader(attestedHeader) + require.NoError(l.t, err) + attestedStateRoot, err := attestedState.HashTreeRoot(ctx) + require.NoError(l.t, err) + + // get a new signed block so the root is updated with the new state root + parent.Block.StateRoot = attestedStateRoot[:] + signedParent, err = blocks.NewSignedBeaconBlock(parent) + require.NoError(l.t, err) + + state, err := util.NewBeaconStateCapella() + require.NoError(l.t, err) + err = state.SetSlot(slot) + require.NoError(l.t, err) + + parentRoot, err := signedParent.Block().HashTreeRoot() + require.NoError(l.t, err) + + block := util.NewBeaconBlockCapella() + block.Block.Slot = slot + block.Block.ParentRoot = parentRoot[:] + + for i := uint64(0); i < params.BeaconConfig().MinSyncCommitteeParticipants; i++ { + block.Block.Body.SyncAggregate.SyncCommitteeBits.SetBitAt(i, true) + if block.Block.Body.SyncAggregate.SyncCommitteeBits.Count()*3 >= params.BeaconConfig().MinSyncCommitteeParticipants*2 { + break + } + } + + signedBlock, err := blocks.NewSignedBeaconBlock(block) + require.NoError(l.t, err) + + h, err := signedBlock.Header() + require.NoError(l.t, err) + + err = state.SetLatestBlockHeader(h.Header) + require.NoError(l.t, err) + stateRoot, err := state.HashTreeRoot(ctx) + require.NoError(l.t, err) + + // get a new signed block so the root is updated with the new state root + block.Block.StateRoot = stateRoot[:] + signedBlock, err = blocks.NewSignedBeaconBlock(block) + require.NoError(l.t, err) + + l.state = state + l.attestedState = attestedState + l.attestedHeader = attestedHeader + l.block = signedBlock + l.ctx = ctx + + return l +} + +func (l *testlc) setupTest_SyncCommitteeBits_Equals_Many() *testlc { + ctx := context.Background() + + slot := primitives.Slot(params.BeaconConfig().AltairForkEpoch * primitives.Epoch(params.BeaconConfig().SlotsPerEpoch)).Add(1) + + attestedState, err := util.NewBeaconStateCapella() + require.NoError(l.t, err) + err = attestedState.SetSlot(slot) + require.NoError(l.t, err) + + parent := util.NewBeaconBlockCapella() + parent.Block.Slot = slot + + signedParent, err := blocks.NewSignedBeaconBlock(parent) + require.NoError(l.t, err) + + parentHeader, err := signedParent.Header() + require.NoError(l.t, err) + attestedHeader := parentHeader.Header + + err = attestedState.SetLatestBlockHeader(attestedHeader) + require.NoError(l.t, err) + attestedStateRoot, err := attestedState.HashTreeRoot(ctx) + require.NoError(l.t, err) + + // get a new signed block so the root is updated with the new state root + parent.Block.StateRoot = attestedStateRoot[:] + signedParent, err = blocks.NewSignedBeaconBlock(parent) + require.NoError(l.t, err) + + state, err := util.NewBeaconStateCapella() + require.NoError(l.t, err) + err = state.SetSlot(slot) + require.NoError(l.t, err) + + parentRoot, err := signedParent.Block().HashTreeRoot() + require.NoError(l.t, err) + + block := util.NewBeaconBlockCapella() + block.Block.Slot = slot + block.Block.ParentRoot = parentRoot[:] + + for i := uint64(0); i < params.BeaconConfig().MinSyncCommitteeParticipants; i++ { + block.Block.Body.SyncAggregate.SyncCommitteeBits.SetBitAt(i, true) + } + + signedBlock, err := blocks.NewSignedBeaconBlock(block) + require.NoError(l.t, err) + + h, err := signedBlock.Header() + require.NoError(l.t, err) + + err = state.SetLatestBlockHeader(h.Header) + require.NoError(l.t, err) + stateRoot, err := state.HashTreeRoot(ctx) + require.NoError(l.t, err) + + // get a new signed block so the root is updated with the new state root + block.Block.StateRoot = stateRoot[:] + signedBlock, err = blocks.NewSignedBeaconBlock(block) + require.NoError(l.t, err) + + l.state = state + l.attestedState = attestedState + l.attestedHeader = attestedHeader + l.block = signedBlock + l.ctx = ctx + + return l +} + +func (l *testlc) checkAttestedHeader(update *ethpbv2.LightClientUpdate) { + require.Equal(l.t, l.attestedHeader.Slot, update.AttestedHeader.Slot, "Attested header slot is not equal") + require.Equal(l.t, l.attestedHeader.ProposerIndex, update.AttestedHeader.ProposerIndex, "Attested header proposer index is not equal") + require.DeepSSZEqual(l.t, l.attestedHeader.ParentRoot, update.AttestedHeader.ParentRoot, "Attested header parent root is not equal") + require.DeepSSZEqual(l.t, l.attestedHeader.BodyRoot, update.AttestedHeader.BodyRoot, "Attested header body root is not equal") + + attestedStateRoot, err := l.attestedState.HashTreeRoot(l.ctx) + require.NoError(l.t, err) + require.DeepSSZEqual(l.t, attestedStateRoot[:], update.AttestedHeader.StateRoot, "Attested header state root is not equal") +} + +func (l *testlc) checkSyncAggregate(update *ethpbv2.LightClientUpdate) { + syncAggregate, err := l.block.Block().Body().SyncAggregate() + require.NoError(l.t, err) + require.DeepSSZEqual(l.t, syncAggregate.SyncCommitteeBits, update.SyncAggregate.SyncCommitteeBits, "SyncAggregate bits is not equal") + require.DeepSSZEqual(l.t, syncAggregate.SyncCommitteeSignature, update.SyncAggregate.SyncCommitteeSignature, "SyncAggregate signature is not equal") +} + +func TestisBetterUpdate_newHasSupermajority_notEquals_oldHasSupermajority(t *testing.T) { + l_old := newTestLc(t).setupTest_SyncCommitteeBits_Equals_Zero() + l_new := newTestLc(t).setupTest_SyncCommitteeBits_Equals_MoreThanTwoThirds() + + oldUpdate, err := blockchain.NewLightClientOptimisticUpdateFromBeaconState(l_old.ctx, l_old.state, l_old.block, l_old.attestedState) + require.NoError(t, err) + require.NotNil(t, oldUpdate, "old update is nil") + newUpdate, err := blockchain.NewLightClientOptimisticUpdateFromBeaconState(l_new.ctx, l_new.state, l_new.block, l_new.attestedState) + require.NoError(t, err) + require.NotNil(t, newUpdate, "new update is nil") + + l_old.checkAttestedHeader(oldUpdate) + l_old.checkSyncAggregate(oldUpdate) + l_new.checkAttestedHeader(newUpdate) + l_new.checkSyncAggregate(newUpdate) + + require.Equal(t, true, isBetterUpdate(newUpdate, oldUpdate)) +} From 7d9a99c83f5020adbf6a9ea032d0ead53cff9703 Mon Sep 17 00:00:00 2001 From: rupam-04 Date: Sun, 14 Jul 2024 03:49:23 +0530 Subject: [PATCH 05/13] chore: capitalise first letter of function names --- beacon-chain/rpc/eth/light-client/helpers.go | 14 +++++++------- beacon-chain/rpc/eth/light-client/helpers_test.go | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/beacon-chain/rpc/eth/light-client/helpers.go b/beacon-chain/rpc/eth/light-client/helpers.go index f942a4e07c2d..7a1078dc0f95 100644 --- a/beacon-chain/rpc/eth/light-client/helpers.go +++ b/beacon-chain/rpc/eth/light-client/helpers.go @@ -314,17 +314,17 @@ func newLightClientUpdateToJSON(input *v2.LightClientUpdate) *structs.LightClien } } -func isSyncCommitteeUpdate(update *ethpbv2.LightClientUpdate) bool { +func IsSyncCommitteeUpdate(update *ethpbv2.LightClientUpdate) bool { nextSyncCommitteeBranch := make([][]byte, fieldparams.NextSyncCommitteeBranchDepth) return !reflect.DeepEqual(update.NextSyncCommitteeBranch, nextSyncCommitteeBranch) } -func isFinalityUpdate(update *ethpbv2.LightClientUpdate) bool { +func IsFinalityUpdate(update *ethpbv2.LightClientUpdate) bool { finalityBranch := make([][]byte, blockchain.FinalityBranchNumOfLeaves) return !reflect.DeepEqual(update.FinalityBranch, finalityBranch) } -func isBetterUpdate(newUpdate, oldUpdate *ethpbv2.LightClientUpdate) bool { +func IsBetterUpdate(newUpdate, oldUpdate *ethpbv2.LightClientUpdate) bool { maxActiveParticipants := newUpdate.SyncAggregate.SyncCommitteeBits.Len() newNumActiveParticipants := newUpdate.SyncAggregate.SyncCommitteeBits.Count() oldNumActiveParticipants := oldUpdate.SyncAggregate.SyncCommitteeBits.Count() @@ -339,16 +339,16 @@ func isBetterUpdate(newUpdate, oldUpdate *ethpbv2.LightClientUpdate) bool { } // Compare presence of relevant sync committee - newHasRelevantSyncCommittee := isSyncCommitteeUpdate(newUpdate) && (slots.SyncCommitteePeriod(slots.ToEpoch(newUpdate.AttestedHeader.Slot)) == slots.SyncCommitteePeriod(slots.ToEpoch(newUpdate.SignatureSlot))) - oldHasRelevantSyncCommittee := isSyncCommitteeUpdate(oldUpdate) && (slots.SyncCommitteePeriod(slots.ToEpoch(oldUpdate.AttestedHeader.Slot)) == slots.SyncCommitteePeriod(slots.ToEpoch(oldUpdate.SignatureSlot))) + newHasRelevantSyncCommittee := IsSyncCommitteeUpdate(newUpdate) && (slots.SyncCommitteePeriod(slots.ToEpoch(newUpdate.AttestedHeader.Slot)) == slots.SyncCommitteePeriod(slots.ToEpoch(newUpdate.SignatureSlot))) + oldHasRelevantSyncCommittee := IsSyncCommitteeUpdate(oldUpdate) && (slots.SyncCommitteePeriod(slots.ToEpoch(oldUpdate.AttestedHeader.Slot)) == slots.SyncCommitteePeriod(slots.ToEpoch(oldUpdate.SignatureSlot))) if newHasRelevantSyncCommittee != oldHasRelevantSyncCommittee { return newHasRelevantSyncCommittee } // Compare indication of any finality - newHasFinality := isFinalityUpdate(newUpdate) - oldHasFinality := isFinalityUpdate(oldUpdate) + newHasFinality := IsFinalityUpdate(newUpdate) + oldHasFinality := IsFinalityUpdate(oldUpdate) if newHasFinality != oldHasFinality { return newHasFinality } diff --git a/beacon-chain/rpc/eth/light-client/helpers_test.go b/beacon-chain/rpc/eth/light-client/helpers_test.go index 97dcb8f73434..f6f20876fe27 100644 --- a/beacon-chain/rpc/eth/light-client/helpers_test.go +++ b/beacon-chain/rpc/eth/light-client/helpers_test.go @@ -259,7 +259,7 @@ func (l *testlc) checkSyncAggregate(update *ethpbv2.LightClientUpdate) { require.DeepSSZEqual(l.t, syncAggregate.SyncCommitteeSignature, update.SyncAggregate.SyncCommitteeSignature, "SyncAggregate signature is not equal") } -func TestisBetterUpdate_newHasSupermajority_notEquals_oldHasSupermajority(t *testing.T) { +func TestIsBetterUpdate_newHasSupermajority_notEquals_oldHasSupermajority(t *testing.T) { l_old := newTestLc(t).setupTest_SyncCommitteeBits_Equals_Zero() l_new := newTestLc(t).setupTest_SyncCommitteeBits_Equals_MoreThanTwoThirds() @@ -275,5 +275,5 @@ func TestisBetterUpdate_newHasSupermajority_notEquals_oldHasSupermajority(t *tes l_new.checkAttestedHeader(newUpdate) l_new.checkSyncAggregate(newUpdate) - require.Equal(t, true, isBetterUpdate(newUpdate, oldUpdate)) + require.Equal(t, true, IsBetterUpdate(newUpdate, oldUpdate)) } From 3e1bf3b27962173d2a5e0b9522813dfbded214c3 Mon Sep 17 00:00:00 2001 From: rupam-04 Date: Mon, 15 Jul 2024 23:29:52 +0530 Subject: [PATCH 06/13] refactor: rewrite test setups in a more readable manner --- beacon-chain/rpc/eth/light-client/helpers.go | 4 +- .../rpc/eth/light-client/helpers_test.go | 375 +++++------------- 2 files changed, 110 insertions(+), 269 deletions(-) diff --git a/beacon-chain/rpc/eth/light-client/helpers.go b/beacon-chain/rpc/eth/light-client/helpers.go index 7a1078dc0f95..59e70b99e7a8 100644 --- a/beacon-chain/rpc/eth/light-client/helpers.go +++ b/beacon-chain/rpc/eth/light-client/helpers.go @@ -355,8 +355,8 @@ func IsBetterUpdate(newUpdate, oldUpdate *ethpbv2.LightClientUpdate) bool { // Compare sync committee finality if newHasFinality { - newHasSyncCommitteeFinality := slots.ToEpoch(newUpdate.FinalizedHeader.Slot) == slots.ToEpoch(newUpdate.AttestedHeader.Slot) - oldHasSyncCommitteeFinality := slots.ToEpoch(oldUpdate.FinalizedHeader.Slot) == slots.ToEpoch(oldUpdate.AttestedHeader.Slot) + newHasSyncCommitteeFinality := slots.SyncCommitteePeriod(slots.ToEpoch(newUpdate.FinalizedHeader.Slot)) == slots.SyncCommitteePeriod(slots.ToEpoch(newUpdate.AttestedHeader.Slot)) + oldHasSyncCommitteeFinality := slots.SyncCommitteePeriod(slots.ToEpoch(oldUpdate.FinalizedHeader.Slot)) == slots.SyncCommitteePeriod(slots.ToEpoch(oldUpdate.AttestedHeader.Slot)) if newHasSyncCommitteeFinality != oldHasSyncCommitteeFinality { return newHasSyncCommitteeFinality diff --git a/beacon-chain/rpc/eth/light-client/helpers_test.go b/beacon-chain/rpc/eth/light-client/helpers_test.go index f6f20876fe27..b0b0694fc90b 100644 --- a/beacon-chain/rpc/eth/light-client/helpers_test.go +++ b/beacon-chain/rpc/eth/light-client/helpers_test.go @@ -1,279 +1,120 @@ package lightclient import ( - "context" "testing" - "github.com/prysmaticlabs/prysm/v5/beacon-chain/blockchain" - "github.com/prysmaticlabs/prysm/v5/beacon-chain/state" - "github.com/prysmaticlabs/prysm/v5/config/params" - "github.com/prysmaticlabs/prysm/v5/consensus-types/blocks" - "github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces" - "github.com/prysmaticlabs/prysm/v5/consensus-types/primitives" ethpbv2 "github.com/prysmaticlabs/prysm/v5/proto/eth/v2" - ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" - "github.com/prysmaticlabs/prysm/v5/testing/require" - "github.com/prysmaticlabs/prysm/v5/testing/util" + "github.com/prysmaticlabs/prysm/v5/testing/assert" ) -type testlc struct { - t *testing.T - ctx context.Context - state state.BeaconState - block interfaces.ReadOnlySignedBeaconBlock - attestedState state.BeaconState - attestedHeader *ethpb.BeaconBlockHeader -} - -func newTestLc(t *testing.T) *testlc { - return &testlc{t: t} -} - -func (l *testlc) setupTest_SyncCommitteeBits_Equals_Zero() *testlc { - ctx := context.Background() - - slot := primitives.Slot(params.BeaconConfig().AltairForkEpoch * primitives.Epoch(params.BeaconConfig().SlotsPerEpoch)).Add(1) - - attestedState, err := util.NewBeaconStateCapella() - require.NoError(l.t, err) - err = attestedState.SetSlot(slot) - require.NoError(l.t, err) - - parent := util.NewBeaconBlockCapella() - parent.Block.Slot = slot - - signedParent, err := blocks.NewSignedBeaconBlock(parent) - require.NoError(l.t, err) - - parentHeader, err := signedParent.Header() - require.NoError(l.t, err) - attestedHeader := parentHeader.Header - - err = attestedState.SetLatestBlockHeader(attestedHeader) - require.NoError(l.t, err) - attestedStateRoot, err := attestedState.HashTreeRoot(ctx) - require.NoError(l.t, err) - - // get a new signed block so the root is updated with the new state root - parent.Block.StateRoot = attestedStateRoot[:] - signedParent, err = blocks.NewSignedBeaconBlock(parent) - require.NoError(l.t, err) - - state, err := util.NewBeaconStateCapella() - require.NoError(l.t, err) - err = state.SetSlot(slot) - require.NoError(l.t, err) - - parentRoot, err := signedParent.Block().HashTreeRoot() - require.NoError(l.t, err) - - block := util.NewBeaconBlockCapella() - block.Block.Slot = slot - block.Block.ParentRoot = parentRoot[:] - - signedBlock, err := blocks.NewSignedBeaconBlock(block) - require.NoError(l.t, err) - - h, err := signedBlock.Header() - require.NoError(l.t, err) - - err = state.SetLatestBlockHeader(h.Header) - require.NoError(l.t, err) - stateRoot, err := state.HashTreeRoot(ctx) - require.NoError(l.t, err) - - // get a new signed block so the root is updated with the new state root - block.Block.StateRoot = stateRoot[:] - signedBlock, err = blocks.NewSignedBeaconBlock(block) - require.NoError(l.t, err) - - l.state = state - l.attestedState = attestedState - l.attestedHeader = attestedHeader - l.block = signedBlock - l.ctx = ctx - - return l -} - -func (l *testlc) setupTest_SyncCommitteeBits_Equals_MoreThanTwoThirds() *testlc { - ctx := context.Background() - - slot := primitives.Slot(params.BeaconConfig().AltairForkEpoch * primitives.Epoch(params.BeaconConfig().SlotsPerEpoch)).Add(1) - - attestedState, err := util.NewBeaconStateCapella() - require.NoError(l.t, err) - err = attestedState.SetSlot(slot) - require.NoError(l.t, err) - - parent := util.NewBeaconBlockCapella() - parent.Block.Slot = slot - - signedParent, err := blocks.NewSignedBeaconBlock(parent) - require.NoError(l.t, err) - - parentHeader, err := signedParent.Header() - require.NoError(l.t, err) - attestedHeader := parentHeader.Header - - err = attestedState.SetLatestBlockHeader(attestedHeader) - require.NoError(l.t, err) - attestedStateRoot, err := attestedState.HashTreeRoot(ctx) - require.NoError(l.t, err) - - // get a new signed block so the root is updated with the new state root - parent.Block.StateRoot = attestedStateRoot[:] - signedParent, err = blocks.NewSignedBeaconBlock(parent) - require.NoError(l.t, err) - - state, err := util.NewBeaconStateCapella() - require.NoError(l.t, err) - err = state.SetSlot(slot) - require.NoError(l.t, err) - - parentRoot, err := signedParent.Block().HashTreeRoot() - require.NoError(l.t, err) - - block := util.NewBeaconBlockCapella() - block.Block.Slot = slot - block.Block.ParentRoot = parentRoot[:] - - for i := uint64(0); i < params.BeaconConfig().MinSyncCommitteeParticipants; i++ { - block.Block.Body.SyncAggregate.SyncCommitteeBits.SetBitAt(i, true) - if block.Block.Body.SyncAggregate.SyncCommitteeBits.Count()*3 >= params.BeaconConfig().MinSyncCommitteeParticipants*2 { - break - } +func TestIsBetterUpdate(t *testing.T) { + testCases := []struct { + name string + oldUpdate *ethpbv2.LightClientUpdate + newUpdate *ethpbv2.LightClientUpdate + expectedResult bool + }{ + { + name: "new has supermajority but old doesn't", + oldUpdate: ðpbv2.LightClientUpdate{}, + newUpdate: ðpbv2.LightClientUpdate{}, + expectedResult: true, + }, + { + name: "old has supermajority but new doesn't", + oldUpdate: ðpbv2.LightClientUpdate{}, + newUpdate: ðpbv2.LightClientUpdate{}, + expectedResult: false, + }, + { + name: "new doesn't have supermajority and newNumActiveParticipants is greater than oldNumActiveParticipants", + oldUpdate: ðpbv2.LightClientUpdate{}, + newUpdate: ðpbv2.LightClientUpdate{}, + expectedResult: true, + }, + { + name: "new doesn't have supermajority and newNumActiveParticipants is lesser than oldNumActiveParticipants", + oldUpdate: ðpbv2.LightClientUpdate{}, + newUpdate: ðpbv2.LightClientUpdate{}, + expectedResult: false, + }, + { + name: "new has relevant sync committee but old doesn't", + oldUpdate: ðpbv2.LightClientUpdate{}, + newUpdate: ðpbv2.LightClientUpdate{}, + expectedResult: true, + }, + { + name: "old has relevant sync committee but new doesn't", + oldUpdate: ðpbv2.LightClientUpdate{}, + newUpdate: ðpbv2.LightClientUpdate{}, + expectedResult: false, + }, + { + name: "new has finality but old doesn't", + oldUpdate: ðpbv2.LightClientUpdate{}, + newUpdate: ðpbv2.LightClientUpdate{}, + expectedResult: true, + }, + { + name: "old has finality but new doesn't", + oldUpdate: ðpbv2.LightClientUpdate{}, + newUpdate: ðpbv2.LightClientUpdate{}, + expectedResult: false, + }, + { + name: "new has finality and sync committee finality both but old doesn't have sync committee finality", + oldUpdate: ðpbv2.LightClientUpdate{}, + newUpdate: ðpbv2.LightClientUpdate{}, + expectedResult: true, + }, + { + name: "new has finality but doesn't have sync committee finality and old has sync committee finality", + oldUpdate: ðpbv2.LightClientUpdate{}, + newUpdate: ðpbv2.LightClientUpdate{}, + expectedResult: false, + }, + { + name: "new has more active participants than old", + oldUpdate: ðpbv2.LightClientUpdate{}, + newUpdate: ðpbv2.LightClientUpdate{}, + expectedResult: true, + }, + { + name: "new has less active participants than old", + oldUpdate: ðpbv2.LightClientUpdate{}, + newUpdate: ðpbv2.LightClientUpdate{}, + expectedResult: false, + }, + { + name: "new's attested header's slot is lesser than old's attested header's slot", + oldUpdate: ðpbv2.LightClientUpdate{}, + newUpdate: ðpbv2.LightClientUpdate{}, + expectedResult: true, + }, + { + name: "new's attested header's slot is greater than old's attested header's slot", + oldUpdate: ðpbv2.LightClientUpdate{}, + newUpdate: ðpbv2.LightClientUpdate{}, + expectedResult: false, + }, + { + name: "none of the above conditions are met and new's signature slot is lesser than old's signature slot", + oldUpdate: ðpbv2.LightClientUpdate{}, + newUpdate: ðpbv2.LightClientUpdate{}, + expectedResult: true, + }, + { + name: "none of the above conditions are met and new's signature slot is greater than old's signature slot", + oldUpdate: ðpbv2.LightClientUpdate{}, + newUpdate: ðpbv2.LightClientUpdate{}, + expectedResult: false, + }, } - signedBlock, err := blocks.NewSignedBeaconBlock(block) - require.NoError(l.t, err) - - h, err := signedBlock.Header() - require.NoError(l.t, err) - - err = state.SetLatestBlockHeader(h.Header) - require.NoError(l.t, err) - stateRoot, err := state.HashTreeRoot(ctx) - require.NoError(l.t, err) - - // get a new signed block so the root is updated with the new state root - block.Block.StateRoot = stateRoot[:] - signedBlock, err = blocks.NewSignedBeaconBlock(block) - require.NoError(l.t, err) - - l.state = state - l.attestedState = attestedState - l.attestedHeader = attestedHeader - l.block = signedBlock - l.ctx = ctx - - return l -} - -func (l *testlc) setupTest_SyncCommitteeBits_Equals_Many() *testlc { - ctx := context.Background() - - slot := primitives.Slot(params.BeaconConfig().AltairForkEpoch * primitives.Epoch(params.BeaconConfig().SlotsPerEpoch)).Add(1) - - attestedState, err := util.NewBeaconStateCapella() - require.NoError(l.t, err) - err = attestedState.SetSlot(slot) - require.NoError(l.t, err) - - parent := util.NewBeaconBlockCapella() - parent.Block.Slot = slot - - signedParent, err := blocks.NewSignedBeaconBlock(parent) - require.NoError(l.t, err) - - parentHeader, err := signedParent.Header() - require.NoError(l.t, err) - attestedHeader := parentHeader.Header - - err = attestedState.SetLatestBlockHeader(attestedHeader) - require.NoError(l.t, err) - attestedStateRoot, err := attestedState.HashTreeRoot(ctx) - require.NoError(l.t, err) - - // get a new signed block so the root is updated with the new state root - parent.Block.StateRoot = attestedStateRoot[:] - signedParent, err = blocks.NewSignedBeaconBlock(parent) - require.NoError(l.t, err) - - state, err := util.NewBeaconStateCapella() - require.NoError(l.t, err) - err = state.SetSlot(slot) - require.NoError(l.t, err) - - parentRoot, err := signedParent.Block().HashTreeRoot() - require.NoError(l.t, err) - - block := util.NewBeaconBlockCapella() - block.Block.Slot = slot - block.Block.ParentRoot = parentRoot[:] - - for i := uint64(0); i < params.BeaconConfig().MinSyncCommitteeParticipants; i++ { - block.Block.Body.SyncAggregate.SyncCommitteeBits.SetBitAt(i, true) + for _, testCase := range testCases { + t.Run(testCase.name, func(t *testing.T) { + assert.Equal(t, testCase.expectedResult, IsBetterUpdate(testCase.newUpdate, testCase.oldUpdate)) + }) } - - signedBlock, err := blocks.NewSignedBeaconBlock(block) - require.NoError(l.t, err) - - h, err := signedBlock.Header() - require.NoError(l.t, err) - - err = state.SetLatestBlockHeader(h.Header) - require.NoError(l.t, err) - stateRoot, err := state.HashTreeRoot(ctx) - require.NoError(l.t, err) - - // get a new signed block so the root is updated with the new state root - block.Block.StateRoot = stateRoot[:] - signedBlock, err = blocks.NewSignedBeaconBlock(block) - require.NoError(l.t, err) - - l.state = state - l.attestedState = attestedState - l.attestedHeader = attestedHeader - l.block = signedBlock - l.ctx = ctx - - return l -} - -func (l *testlc) checkAttestedHeader(update *ethpbv2.LightClientUpdate) { - require.Equal(l.t, l.attestedHeader.Slot, update.AttestedHeader.Slot, "Attested header slot is not equal") - require.Equal(l.t, l.attestedHeader.ProposerIndex, update.AttestedHeader.ProposerIndex, "Attested header proposer index is not equal") - require.DeepSSZEqual(l.t, l.attestedHeader.ParentRoot, update.AttestedHeader.ParentRoot, "Attested header parent root is not equal") - require.DeepSSZEqual(l.t, l.attestedHeader.BodyRoot, update.AttestedHeader.BodyRoot, "Attested header body root is not equal") - - attestedStateRoot, err := l.attestedState.HashTreeRoot(l.ctx) - require.NoError(l.t, err) - require.DeepSSZEqual(l.t, attestedStateRoot[:], update.AttestedHeader.StateRoot, "Attested header state root is not equal") -} - -func (l *testlc) checkSyncAggregate(update *ethpbv2.LightClientUpdate) { - syncAggregate, err := l.block.Block().Body().SyncAggregate() - require.NoError(l.t, err) - require.DeepSSZEqual(l.t, syncAggregate.SyncCommitteeBits, update.SyncAggregate.SyncCommitteeBits, "SyncAggregate bits is not equal") - require.DeepSSZEqual(l.t, syncAggregate.SyncCommitteeSignature, update.SyncAggregate.SyncCommitteeSignature, "SyncAggregate signature is not equal") -} - -func TestIsBetterUpdate_newHasSupermajority_notEquals_oldHasSupermajority(t *testing.T) { - l_old := newTestLc(t).setupTest_SyncCommitteeBits_Equals_Zero() - l_new := newTestLc(t).setupTest_SyncCommitteeBits_Equals_MoreThanTwoThirds() - - oldUpdate, err := blockchain.NewLightClientOptimisticUpdateFromBeaconState(l_old.ctx, l_old.state, l_old.block, l_old.attestedState) - require.NoError(t, err) - require.NotNil(t, oldUpdate, "old update is nil") - newUpdate, err := blockchain.NewLightClientOptimisticUpdateFromBeaconState(l_new.ctx, l_new.state, l_new.block, l_new.attestedState) - require.NoError(t, err) - require.NotNil(t, newUpdate, "new update is nil") - - l_old.checkAttestedHeader(oldUpdate) - l_old.checkSyncAggregate(oldUpdate) - l_new.checkAttestedHeader(newUpdate) - l_new.checkSyncAggregate(newUpdate) - - require.Equal(t, true, IsBetterUpdate(newUpdate, oldUpdate)) } From 9829356580b4517ca08b9dfebd4203a35b52f280 Mon Sep 17 00:00:00 2001 From: rkapka Date: Wed, 17 Jul 2024 19:04:44 +0200 Subject: [PATCH 07/13] two test cases --- beacon-chain/rpc/eth/light-client/BUILD.bazel | 8 ++++- .../rpc/eth/light-client/helpers_test.go | 29 +++++++++++++++---- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/beacon-chain/rpc/eth/light-client/BUILD.bazel b/beacon-chain/rpc/eth/light-client/BUILD.bazel index ade330207cbe..d1afc705fdd9 100644 --- a/beacon-chain/rpc/eth/light-client/BUILD.bazel +++ b/beacon-chain/rpc/eth/light-client/BUILD.bazel @@ -34,7 +34,10 @@ go_library( go_test( name = "go_default_test", - srcs = ["handlers_test.go"], + srcs = [ + "handlers_test.go", + "helpers_test.go", + ], embed = [":go_default_library"], deps = [ "//api/server/structs:go_default_library", @@ -47,7 +50,10 @@ go_test( "//consensus-types/interfaces:go_default_library", "//consensus-types/primitives:go_default_library", "//encoding/bytesutil:go_default_library", + "//proto/eth/v1:go_default_library", + "//proto/eth/v2:go_default_library", "//proto/prysm/v1alpha1:go_default_library", + "//testing/assert:go_default_library", "//testing/require:go_default_library", "//testing/util:go_default_library", "@com_github_ethereum_go_ethereum//common/hexutil:go_default_library", diff --git a/beacon-chain/rpc/eth/light-client/helpers_test.go b/beacon-chain/rpc/eth/light-client/helpers_test.go index b0b0694fc90b..80254373fbdb 100644 --- a/beacon-chain/rpc/eth/light-client/helpers_test.go +++ b/beacon-chain/rpc/eth/light-client/helpers_test.go @@ -3,6 +3,7 @@ package lightclient import ( "testing" + ethpbv1 "github.com/prysmaticlabs/prysm/v5/proto/eth/v1" ethpbv2 "github.com/prysmaticlabs/prysm/v5/proto/eth/v2" "github.com/prysmaticlabs/prysm/v5/testing/assert" ) @@ -15,15 +16,31 @@ func TestIsBetterUpdate(t *testing.T) { expectedResult bool }{ { - name: "new has supermajority but old doesn't", - oldUpdate: ðpbv2.LightClientUpdate{}, - newUpdate: ðpbv2.LightClientUpdate{}, + name: "new has supermajority but old doesn't", + oldUpdate: ðpbv2.LightClientUpdate{ + SyncAggregate: ðpbv1.SyncAggregate{ + SyncCommitteeBits: []byte{0b01111100, 0b1}, + }, + }, + newUpdate: ðpbv2.LightClientUpdate{ + SyncAggregate: ðpbv1.SyncAggregate{ + SyncCommitteeBits: []byte{0b11111100, 0b1}, + }, + }, expectedResult: true, }, { - name: "old has supermajority but new doesn't", - oldUpdate: ðpbv2.LightClientUpdate{}, - newUpdate: ðpbv2.LightClientUpdate{}, + name: "old has supermajority but new doesn't", + oldUpdate: ðpbv2.LightClientUpdate{ + SyncAggregate: ðpbv1.SyncAggregate{ + SyncCommitteeBits: []byte{0b11111100, 0b1}, + }, + }, + newUpdate: ðpbv2.LightClientUpdate{ + SyncAggregate: ðpbv1.SyncAggregate{ + SyncCommitteeBits: []byte{0b01111100, 0b1}, + }, + }, expectedResult: false, }, { From 6e9cbcb608e7093300d135ddec14797790f969d2 Mon Sep 17 00:00:00 2001 From: rupam-04 Date: Fri, 19 Jul 2024 23:32:04 +0530 Subject: [PATCH 08/13] feat: add tests for ``IsBetterUpdate`` --- .../rpc/eth/light-client/helpers_test.go | 394 ++++++++++++++++-- 1 file changed, 348 insertions(+), 46 deletions(-) diff --git a/beacon-chain/rpc/eth/light-client/helpers_test.go b/beacon-chain/rpc/eth/light-client/helpers_test.go index 80254373fbdb..f8f1b321022f 100644 --- a/beacon-chain/rpc/eth/light-client/helpers_test.go +++ b/beacon-chain/rpc/eth/light-client/helpers_test.go @@ -3,6 +3,8 @@ package lightclient import ( "testing" + "github.com/prysmaticlabs/prysm/v5/beacon-chain/blockchain" + fieldparams "github.com/prysmaticlabs/prysm/v5/config/fieldparams" ethpbv1 "github.com/prysmaticlabs/prysm/v5/proto/eth/v1" ethpbv2 "github.com/prysmaticlabs/prysm/v5/proto/eth/v2" "github.com/prysmaticlabs/prysm/v5/testing/assert" @@ -19,12 +21,12 @@ func TestIsBetterUpdate(t *testing.T) { name: "new has supermajority but old doesn't", oldUpdate: ðpbv2.LightClientUpdate{ SyncAggregate: ðpbv1.SyncAggregate{ - SyncCommitteeBits: []byte{0b01111100, 0b1}, + SyncCommitteeBits: []byte{0b01111100, 0b1}, // [0,0,1,1,1,1,1,0] }, }, newUpdate: ðpbv2.LightClientUpdate{ SyncAggregate: ðpbv1.SyncAggregate{ - SyncCommitteeBits: []byte{0b11111100, 0b1}, + SyncCommitteeBits: []byte{0b11111100, 0b1}, // [0,0,1,1,1,1,1,1] }, }, expectedResult: true, @@ -33,98 +35,398 @@ func TestIsBetterUpdate(t *testing.T) { name: "old has supermajority but new doesn't", oldUpdate: ðpbv2.LightClientUpdate{ SyncAggregate: ðpbv1.SyncAggregate{ - SyncCommitteeBits: []byte{0b11111100, 0b1}, + SyncCommitteeBits: []byte{0b11111100, 0b1}, // [0,0,1,1,1,1,1,1] }, }, newUpdate: ðpbv2.LightClientUpdate{ SyncAggregate: ðpbv1.SyncAggregate{ - SyncCommitteeBits: []byte{0b01111100, 0b1}, + SyncCommitteeBits: []byte{0b01111100, 0b1}, // [0,0,1,1,1,1,1,0] }, }, expectedResult: false, }, { - name: "new doesn't have supermajority and newNumActiveParticipants is greater than oldNumActiveParticipants", - oldUpdate: ðpbv2.LightClientUpdate{}, - newUpdate: ðpbv2.LightClientUpdate{}, + name: "new doesn't have supermajority and newNumActiveParticipants is greater than oldNumActiveParticipants", + oldUpdate: ðpbv2.LightClientUpdate{ + SyncAggregate: ðpbv1.SyncAggregate{ + SyncCommitteeBits: []byte{0b00111100, 0b1}, // [0,0,1,1,1,1,0,0] + }, + }, + newUpdate: ðpbv2.LightClientUpdate{ + SyncAggregate: ðpbv1.SyncAggregate{ + SyncCommitteeBits: []byte{0b01111100, 0b1}, // [0,0,1,1,1,1,1,0] + }, + }, expectedResult: true, }, { - name: "new doesn't have supermajority and newNumActiveParticipants is lesser than oldNumActiveParticipants", - oldUpdate: ðpbv2.LightClientUpdate{}, - newUpdate: ðpbv2.LightClientUpdate{}, + name: "new doesn't have supermajority and newNumActiveParticipants is lesser than oldNumActiveParticipants", + oldUpdate: ðpbv2.LightClientUpdate{ + SyncAggregate: ðpbv1.SyncAggregate{ + SyncCommitteeBits: []byte{0b01111100, 0b1}, // [0,0,1,1,1,1,1,0] + }, + }, + newUpdate: ðpbv2.LightClientUpdate{ + SyncAggregate: ðpbv1.SyncAggregate{ + SyncCommitteeBits: []byte{0b00111100, 0b1}, // [0,0,1,1,1,1,0,0] + }, + }, expectedResult: false, }, { - name: "new has relevant sync committee but old doesn't", - oldUpdate: ðpbv2.LightClientUpdate{}, - newUpdate: ðpbv2.LightClientUpdate{}, + name: "new has relevant sync committee but old doesn't", + oldUpdate: ðpbv2.LightClientUpdate{ + SyncAggregate: ðpbv1.SyncAggregate{ + SyncCommitteeBits: []byte{0b00111100, 0b1}, // [0,0,1,1,1,1,0,0] + }, + AttestedHeader: ðpbv1.BeaconBlockHeader{ + Slot: 1000000, + }, + NextSyncCommitteeBranch: make([][]byte, fieldparams.NextSyncCommitteeBranchDepth), + SignatureSlot: 9999, + }, + newUpdate: ðpbv2.LightClientUpdate{ + SyncAggregate: ðpbv1.SyncAggregate{ + SyncCommitteeBits: []byte{0b00111100, 0b1}, // [0,0,1,1,1,1,0,0] + }, + AttestedHeader: ðpbv1.BeaconBlockHeader{ + Slot: 1000001, + }, + NextSyncCommitteeBranch: make([][]byte, 4), + SignatureSlot: 1000000, + }, expectedResult: true, }, { - name: "old has relevant sync committee but new doesn't", - oldUpdate: ðpbv2.LightClientUpdate{}, - newUpdate: ðpbv2.LightClientUpdate{}, + name: "old has relevant sync committee but new doesn't", + oldUpdate: ðpbv2.LightClientUpdate{ + SyncAggregate: ðpbv1.SyncAggregate{ + SyncCommitteeBits: []byte{0b00111100, 0b1}, // [0,0,1,1,1,1,0,0] + }, + AttestedHeader: ðpbv1.BeaconBlockHeader{ + Slot: 1000001, + }, + NextSyncCommitteeBranch: make([][]byte, 4), + SignatureSlot: 1000000, + }, + newUpdate: ðpbv2.LightClientUpdate{ + SyncAggregate: ðpbv1.SyncAggregate{ + SyncCommitteeBits: []byte{0b00111100, 0b1}, // [0,0,1,1,1,1,0,0] + }, + AttestedHeader: ðpbv1.BeaconBlockHeader{ + Slot: 1000000, + }, + NextSyncCommitteeBranch: make([][]byte, fieldparams.NextSyncCommitteeBranchDepth), + SignatureSlot: 9999, + }, expectedResult: false, }, { - name: "new has finality but old doesn't", - oldUpdate: ðpbv2.LightClientUpdate{}, - newUpdate: ðpbv2.LightClientUpdate{}, + name: "new has finality but old doesn't", + oldUpdate: ðpbv2.LightClientUpdate{ + SyncAggregate: ðpbv1.SyncAggregate{ + SyncCommitteeBits: []byte{0b00111100, 0b1}, // [0,0,1,1,1,1,0,0] + }, + AttestedHeader: ðpbv1.BeaconBlockHeader{ + Slot: 1000000, + }, + NextSyncCommitteeBranch: make([][]byte, 4), + SignatureSlot: 9999, + FinalityBranch: make([][]byte, blockchain.FinalityBranchNumOfLeaves), + }, + newUpdate: ðpbv2.LightClientUpdate{ + SyncAggregate: ðpbv1.SyncAggregate{ + SyncCommitteeBits: []byte{0b00111100, 0b1}, // [0,0,1,1,1,1,0,0] + }, + AttestedHeader: ðpbv1.BeaconBlockHeader{ + Slot: 1000000, + }, + NextSyncCommitteeBranch: make([][]byte, 4), + SignatureSlot: 9999, + FinalityBranch: make([][]byte, 5), + }, expectedResult: true, }, { - name: "old has finality but new doesn't", - oldUpdate: ðpbv2.LightClientUpdate{}, - newUpdate: ðpbv2.LightClientUpdate{}, + name: "old has finality but new doesn't", + oldUpdate: ðpbv2.LightClientUpdate{ + SyncAggregate: ðpbv1.SyncAggregate{ + SyncCommitteeBits: []byte{0b00111100, 0b1}, // [0,0,1,1,1,1,0,0] + }, + AttestedHeader: ðpbv1.BeaconBlockHeader{ + Slot: 1000000, + }, + NextSyncCommitteeBranch: make([][]byte, 4), + SignatureSlot: 9999, + FinalityBranch: make([][]byte, 5), + }, + newUpdate: ðpbv2.LightClientUpdate{ + SyncAggregate: ðpbv1.SyncAggregate{ + SyncCommitteeBits: []byte{0b00111100, 0b1}, // [0,0,1,1,1,1,0,0] + }, + AttestedHeader: ðpbv1.BeaconBlockHeader{ + Slot: 1000000, + }, + NextSyncCommitteeBranch: make([][]byte, 4), + SignatureSlot: 9999, + FinalityBranch: make([][]byte, blockchain.FinalityBranchNumOfLeaves), + }, expectedResult: false, }, { - name: "new has finality and sync committee finality both but old doesn't have sync committee finality", - oldUpdate: ðpbv2.LightClientUpdate{}, - newUpdate: ðpbv2.LightClientUpdate{}, + name: "new has finality and sync committee finality both but old doesn't have sync committee finality", + oldUpdate: ðpbv2.LightClientUpdate{ + SyncAggregate: ðpbv1.SyncAggregate{ + SyncCommitteeBits: []byte{0b00111100, 0b1}, // [0,0,1,1,1,1,0,0] + }, + AttestedHeader: ðpbv1.BeaconBlockHeader{ + Slot: 1000000, + }, + NextSyncCommitteeBranch: make([][]byte, 4), + SignatureSlot: 9999, + FinalityBranch: make([][]byte, 5), + FinalizedHeader: ðpbv1.BeaconBlockHeader{ + Slot: 9999, + }, + }, + newUpdate: ðpbv2.LightClientUpdate{ + SyncAggregate: ðpbv1.SyncAggregate{ + SyncCommitteeBits: []byte{0b00111100, 0b1}, // [0,0,1,1,1,1,0,0] + }, + AttestedHeader: ðpbv1.BeaconBlockHeader{ + Slot: 1000000, + }, + NextSyncCommitteeBranch: make([][]byte, 4), + SignatureSlot: 999999, + FinalityBranch: make([][]byte, 5), + FinalizedHeader: ðpbv1.BeaconBlockHeader{ + Slot: 999999, + }, + }, expectedResult: true, }, { - name: "new has finality but doesn't have sync committee finality and old has sync committee finality", - oldUpdate: ðpbv2.LightClientUpdate{}, - newUpdate: ðpbv2.LightClientUpdate{}, + name: "new has finality but doesn't have sync committee finality and old has sync committee finality", + oldUpdate: ðpbv2.LightClientUpdate{ + SyncAggregate: ðpbv1.SyncAggregate{ + SyncCommitteeBits: []byte{0b00111100, 0b1}, // [0,0,1,1,1,1,0,0] + }, + AttestedHeader: ðpbv1.BeaconBlockHeader{ + Slot: 1000000, + }, + NextSyncCommitteeBranch: make([][]byte, 4), + SignatureSlot: 999999, + FinalityBranch: make([][]byte, 5), + FinalizedHeader: ðpbv1.BeaconBlockHeader{ + Slot: 999999, + }, + }, + newUpdate: ðpbv2.LightClientUpdate{ + SyncAggregate: ðpbv1.SyncAggregate{ + SyncCommitteeBits: []byte{0b00111100, 0b1}, // [0,0,1,1,1,1,0,0] + }, + AttestedHeader: ðpbv1.BeaconBlockHeader{ + Slot: 1000000, + }, + NextSyncCommitteeBranch: make([][]byte, 4), + SignatureSlot: 9999, + FinalityBranch: make([][]byte, 5), + FinalizedHeader: ðpbv1.BeaconBlockHeader{ + Slot: 9999, + }, + }, expectedResult: false, }, { - name: "new has more active participants than old", - oldUpdate: ðpbv2.LightClientUpdate{}, - newUpdate: ðpbv2.LightClientUpdate{}, + name: "new has more active participants than old", + oldUpdate: ðpbv2.LightClientUpdate{ + SyncAggregate: ðpbv1.SyncAggregate{ + SyncCommitteeBits: []byte{0b00111100, 0b1}, // [0,0,1,1,1,1,0,0] + }, + AttestedHeader: ðpbv1.BeaconBlockHeader{ + Slot: 1000000, + }, + NextSyncCommitteeBranch: make([][]byte, 4), + SignatureSlot: 9999, + FinalityBranch: make([][]byte, 5), + FinalizedHeader: ðpbv1.BeaconBlockHeader{ + Slot: 9999, + }, + }, + newUpdate: ðpbv2.LightClientUpdate{ + SyncAggregate: ðpbv1.SyncAggregate{ + SyncCommitteeBits: []byte{0b01111100, 0b1}, // [0,1,1,1,1,1,0,0] + }, + AttestedHeader: ðpbv1.BeaconBlockHeader{ + Slot: 1000000, + }, + NextSyncCommitteeBranch: make([][]byte, 4), + SignatureSlot: 9999, + FinalityBranch: make([][]byte, 5), + FinalizedHeader: ðpbv1.BeaconBlockHeader{ + Slot: 9999, + }, + }, expectedResult: true, }, { - name: "new has less active participants than old", - oldUpdate: ðpbv2.LightClientUpdate{}, - newUpdate: ðpbv2.LightClientUpdate{}, + name: "new has less active participants than old", + oldUpdate: ðpbv2.LightClientUpdate{ + SyncAggregate: ðpbv1.SyncAggregate{ + SyncCommitteeBits: []byte{0b01111100, 0b1}, // [0,1,1,1,1,1,0,0] + }, + AttestedHeader: ðpbv1.BeaconBlockHeader{ + Slot: 1000000, + }, + NextSyncCommitteeBranch: make([][]byte, 4), + SignatureSlot: 9999, + FinalityBranch: make([][]byte, 5), + FinalizedHeader: ðpbv1.BeaconBlockHeader{ + Slot: 9999, + }, + }, + newUpdate: ðpbv2.LightClientUpdate{ + SyncAggregate: ðpbv1.SyncAggregate{ + SyncCommitteeBits: []byte{0b00111100, 0b1}, // [0,0,1,1,1,1,0,0] + }, + AttestedHeader: ðpbv1.BeaconBlockHeader{ + Slot: 1000000, + }, + NextSyncCommitteeBranch: make([][]byte, 4), + SignatureSlot: 9999, + FinalityBranch: make([][]byte, 5), + FinalizedHeader: ðpbv1.BeaconBlockHeader{ + Slot: 9999, + }, + }, expectedResult: false, }, { - name: "new's attested header's slot is lesser than old's attested header's slot", - oldUpdate: ðpbv2.LightClientUpdate{}, - newUpdate: ðpbv2.LightClientUpdate{}, + name: "new's attested header's slot is lesser than old's attested header's slot", + oldUpdate: ðpbv2.LightClientUpdate{ + SyncAggregate: ðpbv1.SyncAggregate{ + SyncCommitteeBits: []byte{0b00111100, 0b1}, // [0,0,1,1,1,1,0,0] + }, + AttestedHeader: ðpbv1.BeaconBlockHeader{ + Slot: 1000000, + }, + NextSyncCommitteeBranch: make([][]byte, 4), + SignatureSlot: 9999, + FinalityBranch: make([][]byte, 5), + FinalizedHeader: ðpbv1.BeaconBlockHeader{ + Slot: 9999, + }, + }, + newUpdate: ðpbv2.LightClientUpdate{ + SyncAggregate: ðpbv1.SyncAggregate{ + SyncCommitteeBits: []byte{0b00111100, 0b1}, // [0,0,1,1,1,1,0,0] + }, + AttestedHeader: ðpbv1.BeaconBlockHeader{ + Slot: 999999, + }, + NextSyncCommitteeBranch: make([][]byte, 4), + SignatureSlot: 9999, + FinalityBranch: make([][]byte, 5), + FinalizedHeader: ðpbv1.BeaconBlockHeader{ + Slot: 9999, + }, + }, expectedResult: true, }, { - name: "new's attested header's slot is greater than old's attested header's slot", - oldUpdate: ðpbv2.LightClientUpdate{}, - newUpdate: ðpbv2.LightClientUpdate{}, + name: "new's attested header's slot is greater than old's attested header's slot", + oldUpdate: ðpbv2.LightClientUpdate{ + SyncAggregate: ðpbv1.SyncAggregate{ + SyncCommitteeBits: []byte{0b00111100, 0b1}, // [0,0,1,1,1,1,0,0] + }, + AttestedHeader: ðpbv1.BeaconBlockHeader{ + Slot: 999999, + }, + NextSyncCommitteeBranch: make([][]byte, 4), + SignatureSlot: 9999, + FinalityBranch: make([][]byte, 5), + FinalizedHeader: ðpbv1.BeaconBlockHeader{ + Slot: 9999, + }, + }, + newUpdate: ðpbv2.LightClientUpdate{ + SyncAggregate: ðpbv1.SyncAggregate{ + SyncCommitteeBits: []byte{0b00111100, 0b1}, // [0,0,1,1,1,1,0,0] + }, + AttestedHeader: ðpbv1.BeaconBlockHeader{ + Slot: 1000000, + }, + NextSyncCommitteeBranch: make([][]byte, 4), + SignatureSlot: 9999, + FinalityBranch: make([][]byte, 5), + FinalizedHeader: ðpbv1.BeaconBlockHeader{ + Slot: 9999, + }, + }, expectedResult: false, }, { - name: "none of the above conditions are met and new's signature slot is lesser than old's signature slot", - oldUpdate: ðpbv2.LightClientUpdate{}, - newUpdate: ðpbv2.LightClientUpdate{}, + name: "none of the above conditions are met and new's signature slot is lesser than old's signature slot", + oldUpdate: ðpbv2.LightClientUpdate{ + SyncAggregate: ðpbv1.SyncAggregate{ + SyncCommitteeBits: []byte{0b00111100, 0b1}, // [0,0,1,1,1,1,0,0] + }, + AttestedHeader: ðpbv1.BeaconBlockHeader{ + Slot: 1000000, + }, + NextSyncCommitteeBranch: make([][]byte, 4), + SignatureSlot: 9999, + FinalityBranch: make([][]byte, 5), + FinalizedHeader: ðpbv1.BeaconBlockHeader{ + Slot: 9999, + }, + }, + newUpdate: ðpbv2.LightClientUpdate{ + SyncAggregate: ðpbv1.SyncAggregate{ + SyncCommitteeBits: []byte{0b00111100, 0b1}, // [0,0,1,1,1,1,0,0] + }, + AttestedHeader: ðpbv1.BeaconBlockHeader{ + Slot: 1000000, + }, + NextSyncCommitteeBranch: make([][]byte, 4), + SignatureSlot: 9998, + FinalityBranch: make([][]byte, 5), + FinalizedHeader: ðpbv1.BeaconBlockHeader{ + Slot: 9999, + }, + }, expectedResult: true, }, { - name: "none of the above conditions are met and new's signature slot is greater than old's signature slot", - oldUpdate: ðpbv2.LightClientUpdate{}, - newUpdate: ðpbv2.LightClientUpdate{}, + name: "none of the above conditions are met and new's signature slot is greater than old's signature slot", + oldUpdate: ðpbv2.LightClientUpdate{ + SyncAggregate: ðpbv1.SyncAggregate{ + SyncCommitteeBits: []byte{0b00111100, 0b1}, // [0,0,1,1,1,1,0,0] + }, + AttestedHeader: ðpbv1.BeaconBlockHeader{ + Slot: 1000000, + }, + NextSyncCommitteeBranch: make([][]byte, 4), + SignatureSlot: 9998, + FinalityBranch: make([][]byte, 5), + FinalizedHeader: ðpbv1.BeaconBlockHeader{ + Slot: 9999, + }, + }, + newUpdate: ðpbv2.LightClientUpdate{ + SyncAggregate: ðpbv1.SyncAggregate{ + SyncCommitteeBits: []byte{0b00111100, 0b1}, // [0,0,1,1,1,1,0,0] + }, + AttestedHeader: ðpbv1.BeaconBlockHeader{ + Slot: 1000000, + }, + NextSyncCommitteeBranch: make([][]byte, 4), + SignatureSlot: 9999, + FinalityBranch: make([][]byte, 5), + FinalizedHeader: ðpbv1.BeaconBlockHeader{ + Slot: 9999, + }, + }, expectedResult: false, }, } From f7036ec79339ad8618dbd1772f8b5271506d1e57 Mon Sep 17 00:00:00 2001 From: rupam-04 Date: Fri, 19 Jul 2024 23:33:40 +0530 Subject: [PATCH 09/13] refactor: remove double import --- beacon-chain/rpc/eth/light-client/helpers.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/beacon-chain/rpc/eth/light-client/helpers.go b/beacon-chain/rpc/eth/light-client/helpers.go index 59e70b99e7a8..d6fe7a22f9dd 100644 --- a/beacon-chain/rpc/eth/light-client/helpers.go +++ b/beacon-chain/rpc/eth/light-client/helpers.go @@ -14,7 +14,6 @@ import ( "github.com/prysmaticlabs/prysm/v5/config/params" "github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces" v1 "github.com/prysmaticlabs/prysm/v5/proto/eth/v1" - ethpbv2 "github.com/prysmaticlabs/prysm/v5/proto/eth/v2" v2 "github.com/prysmaticlabs/prysm/v5/proto/eth/v2" "github.com/prysmaticlabs/prysm/v5/proto/migration" "github.com/prysmaticlabs/prysm/v5/time/slots" @@ -314,17 +313,17 @@ func newLightClientUpdateToJSON(input *v2.LightClientUpdate) *structs.LightClien } } -func IsSyncCommitteeUpdate(update *ethpbv2.LightClientUpdate) bool { +func IsSyncCommitteeUpdate(update *v2.LightClientUpdate) bool { nextSyncCommitteeBranch := make([][]byte, fieldparams.NextSyncCommitteeBranchDepth) return !reflect.DeepEqual(update.NextSyncCommitteeBranch, nextSyncCommitteeBranch) } -func IsFinalityUpdate(update *ethpbv2.LightClientUpdate) bool { +func IsFinalityUpdate(update *v2.LightClientUpdate) bool { finalityBranch := make([][]byte, blockchain.FinalityBranchNumOfLeaves) return !reflect.DeepEqual(update.FinalityBranch, finalityBranch) } -func IsBetterUpdate(newUpdate, oldUpdate *ethpbv2.LightClientUpdate) bool { +func IsBetterUpdate(newUpdate, oldUpdate *v2.LightClientUpdate) bool { maxActiveParticipants := newUpdate.SyncAggregate.SyncCommitteeBits.Len() newNumActiveParticipants := newUpdate.SyncAggregate.SyncCommitteeBits.Count() oldNumActiveParticipants := oldUpdate.SyncAggregate.SyncCommitteeBits.Count() From b10300769554b73ca9bc9da8a15083933d2db669 Mon Sep 17 00:00:00 2001 From: Rupam Dey <117000803+rupam-04@users.noreply.github.com> Date: Mon, 22 Jul 2024 21:40:27 +0530 Subject: [PATCH 10/13] wording fix 1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: RadosÅ‚aw Kapka --- beacon-chain/rpc/eth/light-client/helpers_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/beacon-chain/rpc/eth/light-client/helpers_test.go b/beacon-chain/rpc/eth/light-client/helpers_test.go index f8f1b321022f..86cc54782600 100644 --- a/beacon-chain/rpc/eth/light-client/helpers_test.go +++ b/beacon-chain/rpc/eth/light-client/helpers_test.go @@ -398,7 +398,7 @@ func TestIsBetterUpdate(t *testing.T) { expectedResult: true, }, { - name: "none of the above conditions are met and new's signature slot is greater than old's signature slot", + name: "none of the above conditions are met and new signature's slot is greater than old signature's slot", oldUpdate: ðpbv2.LightClientUpdate{ SyncAggregate: ðpbv1.SyncAggregate{ SyncCommitteeBits: []byte{0b00111100, 0b1}, // [0,0,1,1,1,1,0,0] From 187d39025613f5078bd6857ab5814ec074b69150 Mon Sep 17 00:00:00 2001 From: Rupam Dey <117000803+rupam-04@users.noreply.github.com> Date: Mon, 22 Jul 2024 21:40:45 +0530 Subject: [PATCH 11/13] wording fix 2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: RadosÅ‚aw Kapka --- beacon-chain/rpc/eth/light-client/helpers_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/beacon-chain/rpc/eth/light-client/helpers_test.go b/beacon-chain/rpc/eth/light-client/helpers_test.go index 86cc54782600..aa6bdd5cef02 100644 --- a/beacon-chain/rpc/eth/light-client/helpers_test.go +++ b/beacon-chain/rpc/eth/light-client/helpers_test.go @@ -366,7 +366,7 @@ func TestIsBetterUpdate(t *testing.T) { expectedResult: false, }, { - name: "none of the above conditions are met and new's signature slot is lesser than old's signature slot", + name: "none of the above conditions are met and new signature's slot is lesser than old signature's slot", oldUpdate: ðpbv2.LightClientUpdate{ SyncAggregate: ðpbv1.SyncAggregate{ SyncCommitteeBits: []byte{0b00111100, 0b1}, // [0,0,1,1,1,1,0,0] From a31c8f7b230534f8e8bd23a7d1f2e81c9ad4387f Mon Sep 17 00:00:00 2001 From: rupam-04 Date: Tue, 23 Jul 2024 19:40:13 +0530 Subject: [PATCH 12/13] minor fixes --- .../rpc/eth/light-client/helpers_test.go | 94 +++++++++++-------- 1 file changed, 54 insertions(+), 40 deletions(-) diff --git a/beacon-chain/rpc/eth/light-client/helpers_test.go b/beacon-chain/rpc/eth/light-client/helpers_test.go index aa6bdd5cef02..694c73de58db 100644 --- a/beacon-chain/rpc/eth/light-client/helpers_test.go +++ b/beacon-chain/rpc/eth/light-client/helpers_test.go @@ -10,6 +10,20 @@ import ( "github.com/prysmaticlabs/prysm/v5/testing/assert" ) +// When the update has relevant sync committee +func CreateNonEmptySyncCommitteeBranch() [][]byte { + res := make([][]byte, fieldparams.NextSyncCommitteeBranchDepth) + res[0] = []byte("xyz") + return res +} + +// When the update has finality +func CreateNonEmptyFinalityBranch() [][]byte { + res := make([][]byte, blockchain.FinalityBranchNumOfLeaves) + res[0] = []byte("xyz") + return res +} + func TestIsBetterUpdate(t *testing.T) { testCases := []struct { name string @@ -92,7 +106,7 @@ func TestIsBetterUpdate(t *testing.T) { AttestedHeader: ðpbv1.BeaconBlockHeader{ Slot: 1000001, }, - NextSyncCommitteeBranch: make([][]byte, 4), + NextSyncCommitteeBranch: CreateNonEmptySyncCommitteeBranch(), SignatureSlot: 1000000, }, expectedResult: true, @@ -106,7 +120,7 @@ func TestIsBetterUpdate(t *testing.T) { AttestedHeader: ðpbv1.BeaconBlockHeader{ Slot: 1000001, }, - NextSyncCommitteeBranch: make([][]byte, 4), + NextSyncCommitteeBranch: CreateNonEmptySyncCommitteeBranch(), SignatureSlot: 1000000, }, newUpdate: ðpbv2.LightClientUpdate{ @@ -130,7 +144,7 @@ func TestIsBetterUpdate(t *testing.T) { AttestedHeader: ðpbv1.BeaconBlockHeader{ Slot: 1000000, }, - NextSyncCommitteeBranch: make([][]byte, 4), + NextSyncCommitteeBranch: CreateNonEmptySyncCommitteeBranch(), SignatureSlot: 9999, FinalityBranch: make([][]byte, blockchain.FinalityBranchNumOfLeaves), }, @@ -141,9 +155,9 @@ func TestIsBetterUpdate(t *testing.T) { AttestedHeader: ðpbv1.BeaconBlockHeader{ Slot: 1000000, }, - NextSyncCommitteeBranch: make([][]byte, 4), + NextSyncCommitteeBranch: CreateNonEmptySyncCommitteeBranch(), SignatureSlot: 9999, - FinalityBranch: make([][]byte, 5), + FinalityBranch: CreateNonEmptyFinalityBranch(), }, expectedResult: true, }, @@ -156,9 +170,9 @@ func TestIsBetterUpdate(t *testing.T) { AttestedHeader: ðpbv1.BeaconBlockHeader{ Slot: 1000000, }, - NextSyncCommitteeBranch: make([][]byte, 4), + NextSyncCommitteeBranch: CreateNonEmptySyncCommitteeBranch(), SignatureSlot: 9999, - FinalityBranch: make([][]byte, 5), + FinalityBranch: CreateNonEmptyFinalityBranch(), }, newUpdate: ðpbv2.LightClientUpdate{ SyncAggregate: ðpbv1.SyncAggregate{ @@ -167,7 +181,7 @@ func TestIsBetterUpdate(t *testing.T) { AttestedHeader: ðpbv1.BeaconBlockHeader{ Slot: 1000000, }, - NextSyncCommitteeBranch: make([][]byte, 4), + NextSyncCommitteeBranch: CreateNonEmptySyncCommitteeBranch(), SignatureSlot: 9999, FinalityBranch: make([][]byte, blockchain.FinalityBranchNumOfLeaves), }, @@ -182,9 +196,9 @@ func TestIsBetterUpdate(t *testing.T) { AttestedHeader: ðpbv1.BeaconBlockHeader{ Slot: 1000000, }, - NextSyncCommitteeBranch: make([][]byte, 4), + NextSyncCommitteeBranch: CreateNonEmptySyncCommitteeBranch(), SignatureSlot: 9999, - FinalityBranch: make([][]byte, 5), + FinalityBranch: CreateNonEmptyFinalityBranch(), FinalizedHeader: ðpbv1.BeaconBlockHeader{ Slot: 9999, }, @@ -196,9 +210,9 @@ func TestIsBetterUpdate(t *testing.T) { AttestedHeader: ðpbv1.BeaconBlockHeader{ Slot: 1000000, }, - NextSyncCommitteeBranch: make([][]byte, 4), + NextSyncCommitteeBranch: CreateNonEmptySyncCommitteeBranch(), SignatureSlot: 999999, - FinalityBranch: make([][]byte, 5), + FinalityBranch: CreateNonEmptyFinalityBranch(), FinalizedHeader: ðpbv1.BeaconBlockHeader{ Slot: 999999, }, @@ -214,9 +228,9 @@ func TestIsBetterUpdate(t *testing.T) { AttestedHeader: ðpbv1.BeaconBlockHeader{ Slot: 1000000, }, - NextSyncCommitteeBranch: make([][]byte, 4), + NextSyncCommitteeBranch: CreateNonEmptySyncCommitteeBranch(), SignatureSlot: 999999, - FinalityBranch: make([][]byte, 5), + FinalityBranch: CreateNonEmptyFinalityBranch(), FinalizedHeader: ðpbv1.BeaconBlockHeader{ Slot: 999999, }, @@ -228,9 +242,9 @@ func TestIsBetterUpdate(t *testing.T) { AttestedHeader: ðpbv1.BeaconBlockHeader{ Slot: 1000000, }, - NextSyncCommitteeBranch: make([][]byte, 4), + NextSyncCommitteeBranch: CreateNonEmptySyncCommitteeBranch(), SignatureSlot: 9999, - FinalityBranch: make([][]byte, 5), + FinalityBranch: CreateNonEmptyFinalityBranch(), FinalizedHeader: ðpbv1.BeaconBlockHeader{ Slot: 9999, }, @@ -246,9 +260,9 @@ func TestIsBetterUpdate(t *testing.T) { AttestedHeader: ðpbv1.BeaconBlockHeader{ Slot: 1000000, }, - NextSyncCommitteeBranch: make([][]byte, 4), + NextSyncCommitteeBranch: CreateNonEmptySyncCommitteeBranch(), SignatureSlot: 9999, - FinalityBranch: make([][]byte, 5), + FinalityBranch: CreateNonEmptyFinalityBranch(), FinalizedHeader: ðpbv1.BeaconBlockHeader{ Slot: 9999, }, @@ -260,9 +274,9 @@ func TestIsBetterUpdate(t *testing.T) { AttestedHeader: ðpbv1.BeaconBlockHeader{ Slot: 1000000, }, - NextSyncCommitteeBranch: make([][]byte, 4), + NextSyncCommitteeBranch: CreateNonEmptySyncCommitteeBranch(), SignatureSlot: 9999, - FinalityBranch: make([][]byte, 5), + FinalityBranch: CreateNonEmptyFinalityBranch(), FinalizedHeader: ðpbv1.BeaconBlockHeader{ Slot: 9999, }, @@ -278,9 +292,9 @@ func TestIsBetterUpdate(t *testing.T) { AttestedHeader: ðpbv1.BeaconBlockHeader{ Slot: 1000000, }, - NextSyncCommitteeBranch: make([][]byte, 4), + NextSyncCommitteeBranch: CreateNonEmptySyncCommitteeBranch(), SignatureSlot: 9999, - FinalityBranch: make([][]byte, 5), + FinalityBranch: CreateNonEmptyFinalityBranch(), FinalizedHeader: ðpbv1.BeaconBlockHeader{ Slot: 9999, }, @@ -292,9 +306,9 @@ func TestIsBetterUpdate(t *testing.T) { AttestedHeader: ðpbv1.BeaconBlockHeader{ Slot: 1000000, }, - NextSyncCommitteeBranch: make([][]byte, 4), + NextSyncCommitteeBranch: CreateNonEmptySyncCommitteeBranch(), SignatureSlot: 9999, - FinalityBranch: make([][]byte, 5), + FinalityBranch: CreateNonEmptyFinalityBranch(), FinalizedHeader: ðpbv1.BeaconBlockHeader{ Slot: 9999, }, @@ -310,9 +324,9 @@ func TestIsBetterUpdate(t *testing.T) { AttestedHeader: ðpbv1.BeaconBlockHeader{ Slot: 1000000, }, - NextSyncCommitteeBranch: make([][]byte, 4), + NextSyncCommitteeBranch: CreateNonEmptySyncCommitteeBranch(), SignatureSlot: 9999, - FinalityBranch: make([][]byte, 5), + FinalityBranch: CreateNonEmptyFinalityBranch(), FinalizedHeader: ðpbv1.BeaconBlockHeader{ Slot: 9999, }, @@ -324,9 +338,9 @@ func TestIsBetterUpdate(t *testing.T) { AttestedHeader: ðpbv1.BeaconBlockHeader{ Slot: 999999, }, - NextSyncCommitteeBranch: make([][]byte, 4), + NextSyncCommitteeBranch: CreateNonEmptySyncCommitteeBranch(), SignatureSlot: 9999, - FinalityBranch: make([][]byte, 5), + FinalityBranch: CreateNonEmptyFinalityBranch(), FinalizedHeader: ðpbv1.BeaconBlockHeader{ Slot: 9999, }, @@ -342,9 +356,9 @@ func TestIsBetterUpdate(t *testing.T) { AttestedHeader: ðpbv1.BeaconBlockHeader{ Slot: 999999, }, - NextSyncCommitteeBranch: make([][]byte, 4), + NextSyncCommitteeBranch: CreateNonEmptySyncCommitteeBranch(), SignatureSlot: 9999, - FinalityBranch: make([][]byte, 5), + FinalityBranch: CreateNonEmptyFinalityBranch(), FinalizedHeader: ðpbv1.BeaconBlockHeader{ Slot: 9999, }, @@ -356,9 +370,9 @@ func TestIsBetterUpdate(t *testing.T) { AttestedHeader: ðpbv1.BeaconBlockHeader{ Slot: 1000000, }, - NextSyncCommitteeBranch: make([][]byte, 4), + NextSyncCommitteeBranch: CreateNonEmptySyncCommitteeBranch(), SignatureSlot: 9999, - FinalityBranch: make([][]byte, 5), + FinalityBranch: CreateNonEmptyFinalityBranch(), FinalizedHeader: ðpbv1.BeaconBlockHeader{ Slot: 9999, }, @@ -374,9 +388,9 @@ func TestIsBetterUpdate(t *testing.T) { AttestedHeader: ðpbv1.BeaconBlockHeader{ Slot: 1000000, }, - NextSyncCommitteeBranch: make([][]byte, 4), + NextSyncCommitteeBranch: CreateNonEmptySyncCommitteeBranch(), SignatureSlot: 9999, - FinalityBranch: make([][]byte, 5), + FinalityBranch: CreateNonEmptyFinalityBranch(), FinalizedHeader: ðpbv1.BeaconBlockHeader{ Slot: 9999, }, @@ -388,9 +402,9 @@ func TestIsBetterUpdate(t *testing.T) { AttestedHeader: ðpbv1.BeaconBlockHeader{ Slot: 1000000, }, - NextSyncCommitteeBranch: make([][]byte, 4), + NextSyncCommitteeBranch: CreateNonEmptySyncCommitteeBranch(), SignatureSlot: 9998, - FinalityBranch: make([][]byte, 5), + FinalityBranch: CreateNonEmptyFinalityBranch(), FinalizedHeader: ðpbv1.BeaconBlockHeader{ Slot: 9999, }, @@ -406,9 +420,9 @@ func TestIsBetterUpdate(t *testing.T) { AttestedHeader: ðpbv1.BeaconBlockHeader{ Slot: 1000000, }, - NextSyncCommitteeBranch: make([][]byte, 4), + NextSyncCommitteeBranch: CreateNonEmptySyncCommitteeBranch(), SignatureSlot: 9998, - FinalityBranch: make([][]byte, 5), + FinalityBranch: CreateNonEmptyFinalityBranch(), FinalizedHeader: ðpbv1.BeaconBlockHeader{ Slot: 9999, }, @@ -420,9 +434,9 @@ func TestIsBetterUpdate(t *testing.T) { AttestedHeader: ðpbv1.BeaconBlockHeader{ Slot: 1000000, }, - NextSyncCommitteeBranch: make([][]byte, 4), + NextSyncCommitteeBranch: CreateNonEmptySyncCommitteeBranch(), SignatureSlot: 9999, - FinalityBranch: make([][]byte, 5), + FinalityBranch: CreateNonEmptyFinalityBranch(), FinalizedHeader: ðpbv1.BeaconBlockHeader{ Slot: 9999, }, From d57fb0b5e9f450278d4e7ef27b1f4ef0a1d19f72 Mon Sep 17 00:00:00 2001 From: rupam-04 Date: Wed, 24 Jul 2024 00:24:13 +0530 Subject: [PATCH 13/13] fix: change function names to lowercase and fix dependencies --- beacon-chain/rpc/eth/light-client/BUILD.bazel | 2 + .../rpc/eth/light-client/helpers_test.go | 84 +++++++++---------- 2 files changed, 44 insertions(+), 42 deletions(-) diff --git a/beacon-chain/rpc/eth/light-client/BUILD.bazel b/beacon-chain/rpc/eth/light-client/BUILD.bazel index d1afc705fdd9..db4370fd4ede 100644 --- a/beacon-chain/rpc/eth/light-client/BUILD.bazel +++ b/beacon-chain/rpc/eth/light-client/BUILD.bazel @@ -41,10 +41,12 @@ go_test( embed = [":go_default_library"], deps = [ "//api/server/structs:go_default_library", + "//beacon-chain/blockchain:go_default_library", "//beacon-chain/blockchain/testing:go_default_library", "//beacon-chain/core/helpers:go_default_library", "//beacon-chain/rpc/testutil:go_default_library", "//beacon-chain/state:go_default_library", + "//config/fieldparams:go_default_library", "//config/params:go_default_library", "//consensus-types/blocks:go_default_library", "//consensus-types/interfaces:go_default_library", diff --git a/beacon-chain/rpc/eth/light-client/helpers_test.go b/beacon-chain/rpc/eth/light-client/helpers_test.go index 694c73de58db..97a817717c29 100644 --- a/beacon-chain/rpc/eth/light-client/helpers_test.go +++ b/beacon-chain/rpc/eth/light-client/helpers_test.go @@ -11,14 +11,14 @@ import ( ) // When the update has relevant sync committee -func CreateNonEmptySyncCommitteeBranch() [][]byte { +func createNonEmptySyncCommitteeBranch() [][]byte { res := make([][]byte, fieldparams.NextSyncCommitteeBranchDepth) res[0] = []byte("xyz") return res } // When the update has finality -func CreateNonEmptyFinalityBranch() [][]byte { +func createNonEmptyFinalityBranch() [][]byte { res := make([][]byte, blockchain.FinalityBranchNumOfLeaves) res[0] = []byte("xyz") return res @@ -106,7 +106,7 @@ func TestIsBetterUpdate(t *testing.T) { AttestedHeader: ðpbv1.BeaconBlockHeader{ Slot: 1000001, }, - NextSyncCommitteeBranch: CreateNonEmptySyncCommitteeBranch(), + NextSyncCommitteeBranch: createNonEmptySyncCommitteeBranch(), SignatureSlot: 1000000, }, expectedResult: true, @@ -120,7 +120,7 @@ func TestIsBetterUpdate(t *testing.T) { AttestedHeader: ðpbv1.BeaconBlockHeader{ Slot: 1000001, }, - NextSyncCommitteeBranch: CreateNonEmptySyncCommitteeBranch(), + NextSyncCommitteeBranch: createNonEmptySyncCommitteeBranch(), SignatureSlot: 1000000, }, newUpdate: ðpbv2.LightClientUpdate{ @@ -144,7 +144,7 @@ func TestIsBetterUpdate(t *testing.T) { AttestedHeader: ðpbv1.BeaconBlockHeader{ Slot: 1000000, }, - NextSyncCommitteeBranch: CreateNonEmptySyncCommitteeBranch(), + NextSyncCommitteeBranch: createNonEmptySyncCommitteeBranch(), SignatureSlot: 9999, FinalityBranch: make([][]byte, blockchain.FinalityBranchNumOfLeaves), }, @@ -155,9 +155,9 @@ func TestIsBetterUpdate(t *testing.T) { AttestedHeader: ðpbv1.BeaconBlockHeader{ Slot: 1000000, }, - NextSyncCommitteeBranch: CreateNonEmptySyncCommitteeBranch(), + NextSyncCommitteeBranch: createNonEmptySyncCommitteeBranch(), SignatureSlot: 9999, - FinalityBranch: CreateNonEmptyFinalityBranch(), + FinalityBranch: createNonEmptyFinalityBranch(), }, expectedResult: true, }, @@ -170,9 +170,9 @@ func TestIsBetterUpdate(t *testing.T) { AttestedHeader: ðpbv1.BeaconBlockHeader{ Slot: 1000000, }, - NextSyncCommitteeBranch: CreateNonEmptySyncCommitteeBranch(), + NextSyncCommitteeBranch: createNonEmptySyncCommitteeBranch(), SignatureSlot: 9999, - FinalityBranch: CreateNonEmptyFinalityBranch(), + FinalityBranch: createNonEmptyFinalityBranch(), }, newUpdate: ðpbv2.LightClientUpdate{ SyncAggregate: ðpbv1.SyncAggregate{ @@ -181,7 +181,7 @@ func TestIsBetterUpdate(t *testing.T) { AttestedHeader: ðpbv1.BeaconBlockHeader{ Slot: 1000000, }, - NextSyncCommitteeBranch: CreateNonEmptySyncCommitteeBranch(), + NextSyncCommitteeBranch: createNonEmptySyncCommitteeBranch(), SignatureSlot: 9999, FinalityBranch: make([][]byte, blockchain.FinalityBranchNumOfLeaves), }, @@ -196,9 +196,9 @@ func TestIsBetterUpdate(t *testing.T) { AttestedHeader: ðpbv1.BeaconBlockHeader{ Slot: 1000000, }, - NextSyncCommitteeBranch: CreateNonEmptySyncCommitteeBranch(), + NextSyncCommitteeBranch: createNonEmptySyncCommitteeBranch(), SignatureSlot: 9999, - FinalityBranch: CreateNonEmptyFinalityBranch(), + FinalityBranch: createNonEmptyFinalityBranch(), FinalizedHeader: ðpbv1.BeaconBlockHeader{ Slot: 9999, }, @@ -210,9 +210,9 @@ func TestIsBetterUpdate(t *testing.T) { AttestedHeader: ðpbv1.BeaconBlockHeader{ Slot: 1000000, }, - NextSyncCommitteeBranch: CreateNonEmptySyncCommitteeBranch(), + NextSyncCommitteeBranch: createNonEmptySyncCommitteeBranch(), SignatureSlot: 999999, - FinalityBranch: CreateNonEmptyFinalityBranch(), + FinalityBranch: createNonEmptyFinalityBranch(), FinalizedHeader: ðpbv1.BeaconBlockHeader{ Slot: 999999, }, @@ -228,9 +228,9 @@ func TestIsBetterUpdate(t *testing.T) { AttestedHeader: ðpbv1.BeaconBlockHeader{ Slot: 1000000, }, - NextSyncCommitteeBranch: CreateNonEmptySyncCommitteeBranch(), + NextSyncCommitteeBranch: createNonEmptySyncCommitteeBranch(), SignatureSlot: 999999, - FinalityBranch: CreateNonEmptyFinalityBranch(), + FinalityBranch: createNonEmptyFinalityBranch(), FinalizedHeader: ðpbv1.BeaconBlockHeader{ Slot: 999999, }, @@ -242,9 +242,9 @@ func TestIsBetterUpdate(t *testing.T) { AttestedHeader: ðpbv1.BeaconBlockHeader{ Slot: 1000000, }, - NextSyncCommitteeBranch: CreateNonEmptySyncCommitteeBranch(), + NextSyncCommitteeBranch: createNonEmptySyncCommitteeBranch(), SignatureSlot: 9999, - FinalityBranch: CreateNonEmptyFinalityBranch(), + FinalityBranch: createNonEmptyFinalityBranch(), FinalizedHeader: ðpbv1.BeaconBlockHeader{ Slot: 9999, }, @@ -260,9 +260,9 @@ func TestIsBetterUpdate(t *testing.T) { AttestedHeader: ðpbv1.BeaconBlockHeader{ Slot: 1000000, }, - NextSyncCommitteeBranch: CreateNonEmptySyncCommitteeBranch(), + NextSyncCommitteeBranch: createNonEmptySyncCommitteeBranch(), SignatureSlot: 9999, - FinalityBranch: CreateNonEmptyFinalityBranch(), + FinalityBranch: createNonEmptyFinalityBranch(), FinalizedHeader: ðpbv1.BeaconBlockHeader{ Slot: 9999, }, @@ -274,9 +274,9 @@ func TestIsBetterUpdate(t *testing.T) { AttestedHeader: ðpbv1.BeaconBlockHeader{ Slot: 1000000, }, - NextSyncCommitteeBranch: CreateNonEmptySyncCommitteeBranch(), + NextSyncCommitteeBranch: createNonEmptySyncCommitteeBranch(), SignatureSlot: 9999, - FinalityBranch: CreateNonEmptyFinalityBranch(), + FinalityBranch: createNonEmptyFinalityBranch(), FinalizedHeader: ðpbv1.BeaconBlockHeader{ Slot: 9999, }, @@ -292,9 +292,9 @@ func TestIsBetterUpdate(t *testing.T) { AttestedHeader: ðpbv1.BeaconBlockHeader{ Slot: 1000000, }, - NextSyncCommitteeBranch: CreateNonEmptySyncCommitteeBranch(), + NextSyncCommitteeBranch: createNonEmptySyncCommitteeBranch(), SignatureSlot: 9999, - FinalityBranch: CreateNonEmptyFinalityBranch(), + FinalityBranch: createNonEmptyFinalityBranch(), FinalizedHeader: ðpbv1.BeaconBlockHeader{ Slot: 9999, }, @@ -306,9 +306,9 @@ func TestIsBetterUpdate(t *testing.T) { AttestedHeader: ðpbv1.BeaconBlockHeader{ Slot: 1000000, }, - NextSyncCommitteeBranch: CreateNonEmptySyncCommitteeBranch(), + NextSyncCommitteeBranch: createNonEmptySyncCommitteeBranch(), SignatureSlot: 9999, - FinalityBranch: CreateNonEmptyFinalityBranch(), + FinalityBranch: createNonEmptyFinalityBranch(), FinalizedHeader: ðpbv1.BeaconBlockHeader{ Slot: 9999, }, @@ -324,9 +324,9 @@ func TestIsBetterUpdate(t *testing.T) { AttestedHeader: ðpbv1.BeaconBlockHeader{ Slot: 1000000, }, - NextSyncCommitteeBranch: CreateNonEmptySyncCommitteeBranch(), + NextSyncCommitteeBranch: createNonEmptySyncCommitteeBranch(), SignatureSlot: 9999, - FinalityBranch: CreateNonEmptyFinalityBranch(), + FinalityBranch: createNonEmptyFinalityBranch(), FinalizedHeader: ðpbv1.BeaconBlockHeader{ Slot: 9999, }, @@ -338,9 +338,9 @@ func TestIsBetterUpdate(t *testing.T) { AttestedHeader: ðpbv1.BeaconBlockHeader{ Slot: 999999, }, - NextSyncCommitteeBranch: CreateNonEmptySyncCommitteeBranch(), + NextSyncCommitteeBranch: createNonEmptySyncCommitteeBranch(), SignatureSlot: 9999, - FinalityBranch: CreateNonEmptyFinalityBranch(), + FinalityBranch: createNonEmptyFinalityBranch(), FinalizedHeader: ðpbv1.BeaconBlockHeader{ Slot: 9999, }, @@ -356,9 +356,9 @@ func TestIsBetterUpdate(t *testing.T) { AttestedHeader: ðpbv1.BeaconBlockHeader{ Slot: 999999, }, - NextSyncCommitteeBranch: CreateNonEmptySyncCommitteeBranch(), + NextSyncCommitteeBranch: createNonEmptySyncCommitteeBranch(), SignatureSlot: 9999, - FinalityBranch: CreateNonEmptyFinalityBranch(), + FinalityBranch: createNonEmptyFinalityBranch(), FinalizedHeader: ðpbv1.BeaconBlockHeader{ Slot: 9999, }, @@ -370,9 +370,9 @@ func TestIsBetterUpdate(t *testing.T) { AttestedHeader: ðpbv1.BeaconBlockHeader{ Slot: 1000000, }, - NextSyncCommitteeBranch: CreateNonEmptySyncCommitteeBranch(), + NextSyncCommitteeBranch: createNonEmptySyncCommitteeBranch(), SignatureSlot: 9999, - FinalityBranch: CreateNonEmptyFinalityBranch(), + FinalityBranch: createNonEmptyFinalityBranch(), FinalizedHeader: ðpbv1.BeaconBlockHeader{ Slot: 9999, }, @@ -388,9 +388,9 @@ func TestIsBetterUpdate(t *testing.T) { AttestedHeader: ðpbv1.BeaconBlockHeader{ Slot: 1000000, }, - NextSyncCommitteeBranch: CreateNonEmptySyncCommitteeBranch(), + NextSyncCommitteeBranch: createNonEmptySyncCommitteeBranch(), SignatureSlot: 9999, - FinalityBranch: CreateNonEmptyFinalityBranch(), + FinalityBranch: createNonEmptyFinalityBranch(), FinalizedHeader: ðpbv1.BeaconBlockHeader{ Slot: 9999, }, @@ -402,9 +402,9 @@ func TestIsBetterUpdate(t *testing.T) { AttestedHeader: ðpbv1.BeaconBlockHeader{ Slot: 1000000, }, - NextSyncCommitteeBranch: CreateNonEmptySyncCommitteeBranch(), + NextSyncCommitteeBranch: createNonEmptySyncCommitteeBranch(), SignatureSlot: 9998, - FinalityBranch: CreateNonEmptyFinalityBranch(), + FinalityBranch: createNonEmptyFinalityBranch(), FinalizedHeader: ðpbv1.BeaconBlockHeader{ Slot: 9999, }, @@ -420,9 +420,9 @@ func TestIsBetterUpdate(t *testing.T) { AttestedHeader: ðpbv1.BeaconBlockHeader{ Slot: 1000000, }, - NextSyncCommitteeBranch: CreateNonEmptySyncCommitteeBranch(), + NextSyncCommitteeBranch: createNonEmptySyncCommitteeBranch(), SignatureSlot: 9998, - FinalityBranch: CreateNonEmptyFinalityBranch(), + FinalityBranch: createNonEmptyFinalityBranch(), FinalizedHeader: ðpbv1.BeaconBlockHeader{ Slot: 9999, }, @@ -434,9 +434,9 @@ func TestIsBetterUpdate(t *testing.T) { AttestedHeader: ðpbv1.BeaconBlockHeader{ Slot: 1000000, }, - NextSyncCommitteeBranch: CreateNonEmptySyncCommitteeBranch(), + NextSyncCommitteeBranch: createNonEmptySyncCommitteeBranch(), SignatureSlot: 9999, - FinalityBranch: CreateNonEmptyFinalityBranch(), + FinalityBranch: createNonEmptyFinalityBranch(), FinalizedHeader: ðpbv1.BeaconBlockHeader{ Slot: 9999, },