mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-10 05:47:59 -05:00
regression do not update on newSlot
This commit is contained in:
@@ -110,6 +110,7 @@ go_test(
|
|||||||
"log_test.go",
|
"log_test.go",
|
||||||
"metrics_test.go",
|
"metrics_test.go",
|
||||||
"mock_test.go",
|
"mock_test.go",
|
||||||
|
"new_slot_test.go",
|
||||||
"pow_block_test.go",
|
"pow_block_test.go",
|
||||||
"process_attestation_test.go",
|
"process_attestation_test.go",
|
||||||
"process_block_test.go",
|
"process_block_test.go",
|
||||||
|
|||||||
@@ -68,12 +68,6 @@ func (s *Service) NewSlot(ctx context.Context, slot types.Slot) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
s.store.SetJustifiedCheckptAndPayloadHash(bj, h)
|
s.store.SetJustifiedCheckptAndPayloadHash(bj, h)
|
||||||
if err := s.cfg.ForkChoiceStore.UpdateJustifiedCheckpoint(bj); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := s.cfg.ForkChoiceStore.UpdateFinalizedCheckpoint(f); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -5,13 +5,17 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/prysmaticlabs/prysm/beacon-chain/blockchain/store"
|
"github.com/prysmaticlabs/prysm/beacon-chain/blockchain/store"
|
||||||
|
"github.com/prysmaticlabs/prysm/beacon-chain/core/blocks"
|
||||||
testDB "github.com/prysmaticlabs/prysm/beacon-chain/db/testing"
|
testDB "github.com/prysmaticlabs/prysm/beacon-chain/db/testing"
|
||||||
|
doublylinkedtree "github.com/prysmaticlabs/prysm/beacon-chain/forkchoice/doubly-linked-tree"
|
||||||
"github.com/prysmaticlabs/prysm/beacon-chain/forkchoice/protoarray"
|
"github.com/prysmaticlabs/prysm/beacon-chain/forkchoice/protoarray"
|
||||||
"github.com/prysmaticlabs/prysm/beacon-chain/state/stategen"
|
"github.com/prysmaticlabs/prysm/beacon-chain/state/stategen"
|
||||||
"github.com/prysmaticlabs/prysm/config/params"
|
"github.com/prysmaticlabs/prysm/config/params"
|
||||||
types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
|
types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
|
||||||
|
"github.com/prysmaticlabs/prysm/consensus-types/wrapper"
|
||||||
"github.com/prysmaticlabs/prysm/encoding/bytesutil"
|
"github.com/prysmaticlabs/prysm/encoding/bytesutil"
|
||||||
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
||||||
|
"github.com/prysmaticlabs/prysm/testing/assert"
|
||||||
"github.com/prysmaticlabs/prysm/testing/require"
|
"github.com/prysmaticlabs/prysm/testing/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -25,10 +29,18 @@ func TestService_newSlot(t *testing.T) {
|
|||||||
}
|
}
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
|
genesisStateRoot := [32]byte{}
|
||||||
|
genesis := blocks.NewGenesisBlock(genesisStateRoot[:])
|
||||||
|
wsb, err := wrapper.WrappedSignedBeaconBlock(genesis)
|
||||||
|
require.NoError(t, err)
|
||||||
|
assert.NoError(t, beaconDB.SaveBlock(ctx, wsb))
|
||||||
|
bj, err := genesis.Block.HashTreeRoot()
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
require.NoError(t, fcs.InsertOptimisticBlock(ctx, 0, [32]byte{}, [32]byte{}, [32]byte{}, 0, 0)) // genesis
|
require.NoError(t, fcs.InsertOptimisticBlock(ctx, 0, [32]byte{}, [32]byte{}, [32]byte{}, 0, 0)) // genesis
|
||||||
require.NoError(t, fcs.InsertOptimisticBlock(ctx, 32, [32]byte{'a'}, [32]byte{}, [32]byte{}, 0, 0)) // finalized
|
require.NoError(t, fcs.InsertOptimisticBlock(ctx, 32, [32]byte{'a'}, [32]byte{}, [32]byte{}, 0, 0)) // finalized
|
||||||
require.NoError(t, fcs.InsertOptimisticBlock(ctx, 64, [32]byte{'b'}, [32]byte{'a'}, [32]byte{}, 0, 0)) // justified
|
require.NoError(t, fcs.InsertOptimisticBlock(ctx, 64, [32]byte{'b'}, [32]byte{'a'}, [32]byte{}, 0, 0)) // justified
|
||||||
require.NoError(t, fcs.InsertOptimisticBlock(ctx, 96, [32]byte{'c'}, [32]byte{'a'}, [32]byte{}, 0, 0)) // best justified
|
require.NoError(t, fcs.InsertOptimisticBlock(ctx, 96, bj, [32]byte{'a'}, [32]byte{}, 0, 0)) // best justified
|
||||||
require.NoError(t, fcs.InsertOptimisticBlock(ctx, 97, [32]byte{'d'}, [32]byte{}, [32]byte{}, 0, 0)) // bad
|
require.NoError(t, fcs.InsertOptimisticBlock(ctx, 97, [32]byte{'d'}, [32]byte{}, [32]byte{}, 0, 0)) // bad
|
||||||
|
|
||||||
type args struct {
|
type args struct {
|
||||||
@@ -48,7 +60,7 @@ func TestService_newSlot(t *testing.T) {
|
|||||||
slot: params.BeaconConfig().SlotsPerEpoch + 1,
|
slot: params.BeaconConfig().SlotsPerEpoch + 1,
|
||||||
finalized: ðpb.Checkpoint{Epoch: 1, Root: bytesutil.PadTo([]byte{'a'}, 32)},
|
finalized: ðpb.Checkpoint{Epoch: 1, Root: bytesutil.PadTo([]byte{'a'}, 32)},
|
||||||
justified: ðpb.Checkpoint{Epoch: 2, Root: bytesutil.PadTo([]byte{'b'}, 32)},
|
justified: ðpb.Checkpoint{Epoch: 2, Root: bytesutil.PadTo([]byte{'b'}, 32)},
|
||||||
bestJustified: ðpb.Checkpoint{Epoch: 3, Root: bytesutil.PadTo([]byte{'c'}, 32)},
|
bestJustified: ðpb.Checkpoint{Epoch: 3, Root: bj[:]},
|
||||||
shouldEqual: false,
|
shouldEqual: false,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -58,7 +70,7 @@ func TestService_newSlot(t *testing.T) {
|
|||||||
slot: params.BeaconConfig().SlotsPerEpoch,
|
slot: params.BeaconConfig().SlotsPerEpoch,
|
||||||
finalized: ðpb.Checkpoint{Epoch: 1, Root: bytesutil.PadTo([]byte{'a'}, 32)},
|
finalized: ðpb.Checkpoint{Epoch: 1, Root: bytesutil.PadTo([]byte{'a'}, 32)},
|
||||||
justified: ðpb.Checkpoint{Epoch: 3, Root: bytesutil.PadTo([]byte{'b'}, 32)},
|
justified: ðpb.Checkpoint{Epoch: 3, Root: bytesutil.PadTo([]byte{'b'}, 32)},
|
||||||
bestJustified: ðpb.Checkpoint{Epoch: 2, Root: bytesutil.PadTo([]byte{'c'}, 32)},
|
bestJustified: ðpb.Checkpoint{Epoch: 2, Root: bj[:]},
|
||||||
shouldEqual: false,
|
shouldEqual: false,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -78,7 +90,7 @@ func TestService_newSlot(t *testing.T) {
|
|||||||
slot: params.BeaconConfig().SlotsPerEpoch,
|
slot: params.BeaconConfig().SlotsPerEpoch,
|
||||||
finalized: ðpb.Checkpoint{Epoch: 1, Root: bytesutil.PadTo([]byte{'a'}, 32)},
|
finalized: ðpb.Checkpoint{Epoch: 1, Root: bytesutil.PadTo([]byte{'a'}, 32)},
|
||||||
justified: ðpb.Checkpoint{Epoch: 2, Root: bytesutil.PadTo([]byte{'b'}, 32)},
|
justified: ðpb.Checkpoint{Epoch: 2, Root: bytesutil.PadTo([]byte{'b'}, 32)},
|
||||||
bestJustified: ðpb.Checkpoint{Epoch: 3, Root: bytesutil.PadTo([]byte{'c'}, 32)},
|
bestJustified: ðpb.Checkpoint{Epoch: 3, Root: bj[:]},
|
||||||
shouldEqual: true,
|
shouldEqual: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -98,3 +110,43 @@ func TestService_newSlot(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestNewSlot_DontUpdateForkchoiceJustification(t *testing.T) {
|
||||||
|
beaconDB := testDB.SetupDB(t)
|
||||||
|
fcs := doublylinkedtree.New(0, 0)
|
||||||
|
opts := []Option{
|
||||||
|
WithDatabase(beaconDB),
|
||||||
|
WithStateGen(stategen.New(beaconDB)),
|
||||||
|
WithForkChoiceStore(fcs),
|
||||||
|
}
|
||||||
|
ctx := context.Background()
|
||||||
|
|
||||||
|
genesisStateRoot := [32]byte{}
|
||||||
|
genesis := blocks.NewGenesisBlock(genesisStateRoot[:])
|
||||||
|
wsb, err := wrapper.WrappedSignedBeaconBlock(genesis)
|
||||||
|
require.NoError(t, err)
|
||||||
|
assert.NoError(t, beaconDB.SaveBlock(ctx, wsb))
|
||||||
|
jr, err := genesis.Block.HashTreeRoot()
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
require.NoError(t, fcs.InsertOptimisticBlock(ctx, 0, [32]byte{}, [32]byte{}, [32]byte{}, 0, 0))
|
||||||
|
require.NoError(t, fcs.InsertOptimisticBlock(ctx, 32, [32]byte{'a'}, [32]byte{}, [32]byte{}, 0, 0))
|
||||||
|
require.NoError(t, fcs.InsertOptimisticBlock(ctx, 64, jr, [32]byte{'a'}, [32]byte{}, 0, 0))
|
||||||
|
gcp := ðpb.Checkpoint{Root: params.BeaconConfig().ZeroHash[:], Epoch: 0}
|
||||||
|
service, err := NewService(ctx, opts...)
|
||||||
|
require.NoError(t, err)
|
||||||
|
s := store.New(gcp, gcp)
|
||||||
|
|
||||||
|
bcp := ðpb.Checkpoint{Root: jr[:], Epoch: 2}
|
||||||
|
s.SetBestJustifiedCheckpt(bcp)
|
||||||
|
service.store = s
|
||||||
|
|
||||||
|
headRoot, err := fcs.Head(ctx, jr, []uint64{})
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, jr, headRoot)
|
||||||
|
|
||||||
|
require.NoError(t, service.NewSlot(ctx, types.Slot(64)))
|
||||||
|
headRoot, err = fcs.Head(ctx, jr, []uint64{})
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, jr, headRoot)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user