Skip to content

Commit

Permalink
fixed fork consensus spec test (#7143)
Browse files Browse the repository at this point in the history
  • Loading branch information
Giulio2002 authored Mar 20, 2023
1 parent 4a1c61a commit 97e1767
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 2 deletions.
51 changes: 51 additions & 0 deletions cmd/ef-tests-cl/consensus_tests/fork.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package consensustests

import (
"fmt"
"os"

"github.com/ledgerwatch/erigon/cl/clparams"
)

func forkTest(context testContext) error {
prevContext := context
prevContext.version--
preState, err := decodeStateFromFile(prevContext, "pre.ssz_snappy")
if err != nil {
return err
}
postState, err := decodeStateFromFile(context, "post.ssz_snappy")
expectedError := os.IsNotExist(err)
if err != nil && !expectedError {
return err
}

if preState.Version() == clparams.Phase0Version {
if err := preState.UpgradeToAltair(); err != nil {
return err
}
} else if preState.Version() == clparams.AltairVersion {
if err := preState.UpgradeToBellatrix(); err != nil {
return err
}
} else if preState.Version() == clparams.BellatrixVersion {
if err := preState.UpgradeToCapella(); err != nil {
return err
}
}
if expectedError {
return fmt.Errorf("expected error")
}
root, err := preState.HashSSZ()
if err != nil {
return err
}
expectedRoot, err := postState.HashSSZ()
if err != nil {
return err
}
if root != expectedRoot {
return fmt.Errorf("mismatching state roots")
}
return nil
}
4 changes: 4 additions & 0 deletions cmd/ef-tests-cl/consensus_tests/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ var (
// transitionCoreTest
var finality = "finality/finality"

// fork
var fork = "fork/fork"

// sanity
var sanityBlocks = "sanity/blocks"
var sanitySlots = "sanity/slots"
Expand Down Expand Up @@ -111,6 +114,7 @@ var handlers map[string]testFunc = map[string]testFunc{
path.Join(sszDivision, signedBeaconBlockCase): getSSZStaticConsensusTest(&cltypes.SignedBeaconBlock{}),
path.Join(sszDivision, beaconBlockCase): getSSZStaticConsensusTest(&cltypes.BeaconBlock{}),
path.Join(sszDivision, beaconBodyCase): getSSZStaticConsensusTest(&cltypes.BeaconBody{}),
fork: forkTest,
transitionCore: transitionTestFunction,
sanityBlocks: testSanityFunction,
sanitySlots: testSanityFunctionSlot,
Expand Down
3 changes: 2 additions & 1 deletion cmd/erigon-cl/core/state/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ func (b *BeaconState) UpgradeToAltair() error {
if err != nil {
return err
}

for _, index := range indicies {
for _, flagIndex := range flags {
b.previousEpochParticipation[index].Add(int(flagIndex))
b.previousEpochParticipation[index] = b.previousEpochParticipation[index].Add(int(flagIndex))
}
}
}
Expand Down
1 change: 0 additions & 1 deletion cmd/sentinel/sentinel/sentinel.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ func (s *Sentinel) pubsubOptions() []pubsub.Option {
pubsubQueueSize := 600
gsp := pubsub.DefaultGossipSubParams()
psOpts := []pubsub.Option{
pubsub.WithMessageSignaturePolicy(pubsub.StrictNoSign),
pubsub.WithMessageSignaturePolicy(pubsub.StrictNoSign),
pubsub.WithMessageIdFn(func(pmsg *pubsub_pb.Message) string {
return fork.MsgID(pmsg, s.cfg.NetworkConfig, s.cfg.BeaconConfig, s.cfg.GenesisConfig)
Expand Down

0 comments on commit 97e1767

Please sign in to comment.