Compare commits

...

2 Commits

Author SHA1 Message Date
terence tsao
f446151d1a Fix 2022-03-24 17:04:45 -07:00
terence tsao
060d646fcf Play 2022-03-24 15:24:57 -07:00
6 changed files with 21 additions and 2 deletions

View File

@@ -3,6 +3,7 @@ package blockchain
import (
"bytes"
"context"
"fmt"
"github.com/pkg/errors"
types "github.com/prysmaticlabs/eth2-types"
@@ -32,6 +33,7 @@ import (
func (s *Service) NewSlot(ctx context.Context, slot types.Slot) error {
// Reset proposer boost root in fork choice.
fmt.Println("Resetting proposer boost root in fork choice")
if err := s.cfg.ForkChoiceStore.ResetBoostedProposerRoot(ctx); err != nil {
return errors.Wrap(err, "could not reset boosted proposer root in fork choice")
}

View File

@@ -2,6 +2,7 @@ package protoarray
import (
"context"
"fmt"
"time"
"github.com/pkg/errors"
@@ -27,6 +28,10 @@ func (f *ForkChoice) BoostProposerRoot(_ context.Context, blockSlot types.Slot,
// Only update the boosted proposer root to the incoming block root
// if the block is for the current, clock-based slot and the block was timely.
fmt.Println(genesisTime.Unix())
fmt.Println(time.Now().Unix())
fmt.Println(timeIntoSlot, secondsPerSlot, params.BeaconConfig().IntervalsPerSlot, secondsPerSlot/params.BeaconConfig().IntervalsPerSlot)
fmt.Println(currentSlot == blockSlot, isBeforeAttestingInterval)
if currentSlot == blockSlot && isBeforeAttestingInterval {
f.store.proposerBoostLock.Lock()
f.store.proposerBoostRoot = blockRoot
@@ -38,6 +43,7 @@ func (f *ForkChoice) BoostProposerRoot(_ context.Context, blockSlot types.Slot,
// ResetBoostedProposerRoot sets the value of the proposer boosted root to zeros.
func (f *ForkChoice) ResetBoostedProposerRoot(_ context.Context) error {
f.store.proposerBoostLock.Lock()
fmt.Println("Resetting boosted proposer root")
f.store.proposerBoostRoot = [32]byte{}
f.store.proposerBoostLock.Unlock()
return nil

View File

@@ -1,6 +1,11 @@
package params
import "testing"
import (
"sync"
"testing"
)
var beaconConfigLock sync.RWMutex
// SetupTestConfigCleanup preserves configurations allowing to modify them within tests without any
// restrictions, everything is restored after the test.
@@ -9,8 +14,10 @@ func SetupTestConfigCleanup(t testing.TB) {
prevBeaconConfig := beaconConfig.Copy()
prevNetworkCfg := networkConfig.Copy()
t.Cleanup(func() {
beaconConfigLock.Lock()
mainnetBeaconConfig = prevDefaultBeaconConfig
beaconConfig = prevBeaconConfig
networkConfig = prevNetworkCfg
beaconConfigLock.Unlock()
})
}

View File

@@ -23,6 +23,7 @@ go_library(
"//beacon-chain/state/v1:go_default_library",
"//beacon-chain/state/v2:go_default_library",
"//beacon-chain/state/v3:go_default_library",
"//config/features:go_default_library",
"//config/fieldparams:go_default_library",
"//config/params:go_default_library",
"//encoding/bytesutil:go_default_library",

View File

@@ -81,6 +81,7 @@ func Run(t *testing.T, config string, fork int) {
service.SetGenesisTime(time.Unix(time.Now().Unix()-newTick, 0))
if newTick > lastTick {
slot := uint64(newTick) / params.BeaconConfig().SecondsPerSlot
fmt.Println("Reset boosting at slot", slot, service.GenesisTime().Unix())
require.NoError(t, service.NewSlot(ctx, types.Slot(slot)))
lastTick = newTick
}
@@ -103,9 +104,11 @@ func Run(t *testing.T, config string, fork int) {
}
r, err := beaconBlock.Block().HashTreeRoot()
require.NoError(t, err)
require.NoError(t, service.ForkChoicer().BoostProposerRoot(ctx, beaconBlock.Block().Slot(), r, service.GenesisTime()))
if step.Valid != nil && !*step.Valid {
require.Equal(t, true, service.ReceiveBlock(ctx, beaconBlock, r) != nil)
} else {
fmt.Println("Process block at slot", beaconBlock.Block().Slot(), service.GenesisTime().Unix())
require.NoError(t, service.ReceiveBlock(ctx, beaconBlock, r))
}
}

View File

@@ -12,7 +12,7 @@ import (
// SetConfig sets the global params for spec tests depending on the option chosen.
// Provides reset function allowing to get back to the previous configuration at the end of a test.
func SetConfig(t testing.TB, config string) error {
params.SetupTestConfigCleanup(t)
//params.SetupTestConfigCleanup(t)
switch config {
case "minimal":
params.OverrideBeaconConfig(params.MinimalSpecConfig())