mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-07 20:43:57 -05:00
Massive code cleanup (#10913)
* Massive code cleanup * fix test issues * remove GetGenesis mock expectations * unused receiver * rename unused params Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
This commit is contained in:
@@ -9,7 +9,7 @@ import (
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
func HttpResponseModifier(ctx context.Context, w http.ResponseWriter, resp proto.Message) error {
|
||||
func HttpResponseModifier(ctx context.Context, w http.ResponseWriter, _ proto.Message) error {
|
||||
md, ok := gwruntime.ServerMetadataFromContext(ctx)
|
||||
if !ok {
|
||||
return nil
|
||||
|
||||
@@ -49,7 +49,7 @@ func (lk *Lock) Lock() {
|
||||
lk.unlock <- 1
|
||||
}
|
||||
|
||||
// Unlocks this lock. Must be called after Lock.
|
||||
// Unlock unlocks this lock. Must be called after Lock.
|
||||
// Can only be invoked if there is a previous call to Lock.
|
||||
func (lk *Lock) Unlock() {
|
||||
<-lk.unlock
|
||||
@@ -65,14 +65,14 @@ func (lk *Lock) Unlock() {
|
||||
<-lk.lock
|
||||
}
|
||||
|
||||
// Temporarily unlocks, gives up the cpu time to other goroutine, and attempts to lock again.
|
||||
// Yield temporarily unlocks, gives up the cpu time to other goroutine, and attempts to lock again.
|
||||
func (lk *Lock) Yield() {
|
||||
lk.Unlock()
|
||||
runtime.Gosched()
|
||||
lk.Lock()
|
||||
}
|
||||
|
||||
// Creates a new multilock for the specified keys
|
||||
// NewMultilock creates a new multilock for the specified keys
|
||||
func NewMultilock(locks ...string) *Lock {
|
||||
if len(locks) == 0 {
|
||||
return nil
|
||||
@@ -87,7 +87,7 @@ func NewMultilock(locks ...string) *Lock {
|
||||
}
|
||||
}
|
||||
|
||||
// Cleans old unused locks. Returns removed keys.
|
||||
// Clean cleans old unused locks. Returns removed keys.
|
||||
func Clean() []string {
|
||||
locks.lock <- 1
|
||||
defer func() { <-locks.lock }()
|
||||
|
||||
@@ -22,22 +22,22 @@ import (
|
||||
|
||||
func TestUnique(t *testing.T) {
|
||||
var arr []string
|
||||
assert := assert.New(t)
|
||||
a := assert.New(t)
|
||||
|
||||
arr = []string{"a", "b", "c"}
|
||||
assert.Equal(arr, unique(arr))
|
||||
a.Equal(arr, unique(arr))
|
||||
|
||||
arr = []string{"a", "a", "a"}
|
||||
assert.Equal([]string{"a"}, unique(arr))
|
||||
a.Equal([]string{"a"}, unique(arr))
|
||||
|
||||
arr = []string{"a", "a", "b"}
|
||||
assert.Equal([]string{"a", "b"}, unique(arr))
|
||||
a.Equal([]string{"a", "b"}, unique(arr))
|
||||
|
||||
arr = []string{"a", "b", "a"}
|
||||
assert.Equal([]string{"a", "b"}, unique(arr))
|
||||
a.Equal([]string{"a", "b"}, unique(arr))
|
||||
|
||||
arr = []string{"a", "b", "c", "b", "d"}
|
||||
assert.Equal([]string{"a", "b", "c", "d"}, unique(arr))
|
||||
a.Equal([]string{"a", "b", "c", "d"}, unique(arr))
|
||||
}
|
||||
|
||||
func TestGetChan(t *testing.T) {
|
||||
@@ -45,9 +45,9 @@ func TestGetChan(t *testing.T) {
|
||||
ch2 := getChan("aa")
|
||||
ch3 := getChan("a")
|
||||
|
||||
assert := assert.New(t)
|
||||
assert.NotEqual(ch1, ch2)
|
||||
assert.Equal(ch1, ch3)
|
||||
a := assert.New(t)
|
||||
a.NotEqual(ch1, ch2)
|
||||
a.Equal(ch1, ch3)
|
||||
}
|
||||
|
||||
func TestLockUnlock(_ *testing.T) {
|
||||
|
||||
@@ -309,21 +309,21 @@ func TestService_ChainHeads_ProtoArray(t *testing.T) {
|
||||
c := &Service{cfg: &config{ForkChoiceStore: protoarray.New()}}
|
||||
ojc := ðpb.Checkpoint{Root: params.BeaconConfig().ZeroHash[:]}
|
||||
ofc := ðpb.Checkpoint{Root: params.BeaconConfig().ZeroHash[:]}
|
||||
state, blkRoot, err := prepareForkchoiceState(ctx, 100, [32]byte{'a'}, [32]byte{}, params.BeaconConfig().ZeroHash, ojc, ofc)
|
||||
st, blkRoot, err := prepareForkchoiceState(ctx, 100, [32]byte{'a'}, [32]byte{}, params.BeaconConfig().ZeroHash, ojc, ofc)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, c.cfg.ForkChoiceStore.InsertNode(ctx, state, blkRoot))
|
||||
state, blkRoot, err = prepareForkchoiceState(ctx, 101, [32]byte{'b'}, [32]byte{'a'}, params.BeaconConfig().ZeroHash, ojc, ofc)
|
||||
require.NoError(t, c.cfg.ForkChoiceStore.InsertNode(ctx, st, blkRoot))
|
||||
st, blkRoot, err = prepareForkchoiceState(ctx, 101, [32]byte{'b'}, [32]byte{'a'}, params.BeaconConfig().ZeroHash, ojc, ofc)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, c.cfg.ForkChoiceStore.InsertNode(ctx, state, blkRoot))
|
||||
state, blkRoot, err = prepareForkchoiceState(ctx, 102, [32]byte{'c'}, [32]byte{'b'}, params.BeaconConfig().ZeroHash, ojc, ofc)
|
||||
require.NoError(t, c.cfg.ForkChoiceStore.InsertNode(ctx, st, blkRoot))
|
||||
st, blkRoot, err = prepareForkchoiceState(ctx, 102, [32]byte{'c'}, [32]byte{'b'}, params.BeaconConfig().ZeroHash, ojc, ofc)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, c.cfg.ForkChoiceStore.InsertNode(ctx, state, blkRoot))
|
||||
state, blkRoot, err = prepareForkchoiceState(ctx, 103, [32]byte{'d'}, [32]byte{'a'}, params.BeaconConfig().ZeroHash, ojc, ofc)
|
||||
require.NoError(t, c.cfg.ForkChoiceStore.InsertNode(ctx, st, blkRoot))
|
||||
st, blkRoot, err = prepareForkchoiceState(ctx, 103, [32]byte{'d'}, [32]byte{'a'}, params.BeaconConfig().ZeroHash, ojc, ofc)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, c.cfg.ForkChoiceStore.InsertNode(ctx, state, blkRoot))
|
||||
state, blkRoot, err = prepareForkchoiceState(ctx, 104, [32]byte{'e'}, [32]byte{'b'}, params.BeaconConfig().ZeroHash, ojc, ofc)
|
||||
require.NoError(t, c.cfg.ForkChoiceStore.InsertNode(ctx, st, blkRoot))
|
||||
st, blkRoot, err = prepareForkchoiceState(ctx, 104, [32]byte{'e'}, [32]byte{'b'}, params.BeaconConfig().ZeroHash, ojc, ofc)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, c.cfg.ForkChoiceStore.InsertNode(ctx, state, blkRoot))
|
||||
require.NoError(t, c.cfg.ForkChoiceStore.InsertNode(ctx, st, blkRoot))
|
||||
|
||||
roots, slots := c.ChainHeads()
|
||||
require.DeepEqual(t, [][32]byte{{'c'}, {'d'}, {'e'}}, roots)
|
||||
@@ -341,24 +341,24 @@ func TestService_ChainHeads_DoublyLinkedTree(t *testing.T) {
|
||||
c := &Service{cfg: &config{ForkChoiceStore: doublylinkedtree.New()}}
|
||||
ojc := ðpb.Checkpoint{Root: params.BeaconConfig().ZeroHash[:]}
|
||||
ofc := ðpb.Checkpoint{Root: params.BeaconConfig().ZeroHash[:]}
|
||||
state, blkRoot, err := prepareForkchoiceState(ctx, 0, [32]byte{}, [32]byte{}, params.BeaconConfig().ZeroHash, ojc, ofc)
|
||||
st, blkRoot, err := prepareForkchoiceState(ctx, 0, [32]byte{}, [32]byte{}, params.BeaconConfig().ZeroHash, ojc, ofc)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, c.cfg.ForkChoiceStore.InsertNode(ctx, state, blkRoot))
|
||||
state, blkRoot, err = prepareForkchoiceState(ctx, 100, [32]byte{'a'}, [32]byte{}, params.BeaconConfig().ZeroHash, ojc, ofc)
|
||||
require.NoError(t, c.cfg.ForkChoiceStore.InsertNode(ctx, st, blkRoot))
|
||||
st, blkRoot, err = prepareForkchoiceState(ctx, 100, [32]byte{'a'}, [32]byte{}, params.BeaconConfig().ZeroHash, ojc, ofc)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, c.cfg.ForkChoiceStore.InsertNode(ctx, state, blkRoot))
|
||||
state, blkRoot, err = prepareForkchoiceState(ctx, 101, [32]byte{'b'}, [32]byte{'a'}, params.BeaconConfig().ZeroHash, ojc, ofc)
|
||||
require.NoError(t, c.cfg.ForkChoiceStore.InsertNode(ctx, st, blkRoot))
|
||||
st, blkRoot, err = prepareForkchoiceState(ctx, 101, [32]byte{'b'}, [32]byte{'a'}, params.BeaconConfig().ZeroHash, ojc, ofc)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, c.cfg.ForkChoiceStore.InsertNode(ctx, state, blkRoot))
|
||||
state, blkRoot, err = prepareForkchoiceState(ctx, 102, [32]byte{'c'}, [32]byte{'b'}, params.BeaconConfig().ZeroHash, ojc, ofc)
|
||||
require.NoError(t, c.cfg.ForkChoiceStore.InsertNode(ctx, st, blkRoot))
|
||||
st, blkRoot, err = prepareForkchoiceState(ctx, 102, [32]byte{'c'}, [32]byte{'b'}, params.BeaconConfig().ZeroHash, ojc, ofc)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, c.cfg.ForkChoiceStore.InsertNode(ctx, state, blkRoot))
|
||||
state, blkRoot, err = prepareForkchoiceState(ctx, 103, [32]byte{'d'}, [32]byte{}, params.BeaconConfig().ZeroHash, ojc, ofc)
|
||||
require.NoError(t, c.cfg.ForkChoiceStore.InsertNode(ctx, st, blkRoot))
|
||||
st, blkRoot, err = prepareForkchoiceState(ctx, 103, [32]byte{'d'}, [32]byte{}, params.BeaconConfig().ZeroHash, ojc, ofc)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, c.cfg.ForkChoiceStore.InsertNode(ctx, state, blkRoot))
|
||||
state, blkRoot, err = prepareForkchoiceState(ctx, 104, [32]byte{'e'}, [32]byte{'b'}, params.BeaconConfig().ZeroHash, ojc, ofc)
|
||||
require.NoError(t, c.cfg.ForkChoiceStore.InsertNode(ctx, st, blkRoot))
|
||||
st, blkRoot, err = prepareForkchoiceState(ctx, 104, [32]byte{'e'}, [32]byte{'b'}, params.BeaconConfig().ZeroHash, ojc, ofc)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, c.cfg.ForkChoiceStore.InsertNode(ctx, state, blkRoot))
|
||||
require.NoError(t, c.cfg.ForkChoiceStore.InsertNode(ctx, st, blkRoot))
|
||||
|
||||
roots, slots := c.ChainHeads()
|
||||
require.Equal(t, 3, len(roots))
|
||||
@@ -438,12 +438,12 @@ func TestService_IsOptimistic_ProtoArray(t *testing.T) {
|
||||
c := &Service{cfg: &config{ForkChoiceStore: protoarray.New()}, head: &head{slot: 101, root: [32]byte{'b'}}}
|
||||
ojc := ðpb.Checkpoint{Root: params.BeaconConfig().ZeroHash[:]}
|
||||
ofc := ðpb.Checkpoint{Root: params.BeaconConfig().ZeroHash[:]}
|
||||
state, blkRoot, err := prepareForkchoiceState(ctx, 100, [32]byte{'a'}, [32]byte{}, params.BeaconConfig().ZeroHash, ojc, ofc)
|
||||
st, blkRoot, err := prepareForkchoiceState(ctx, 100, [32]byte{'a'}, [32]byte{}, params.BeaconConfig().ZeroHash, ojc, ofc)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, c.cfg.ForkChoiceStore.InsertNode(ctx, state, blkRoot))
|
||||
state, blkRoot, err = prepareForkchoiceState(ctx, 101, [32]byte{'b'}, [32]byte{'a'}, params.BeaconConfig().ZeroHash, ojc, ofc)
|
||||
require.NoError(t, c.cfg.ForkChoiceStore.InsertNode(ctx, st, blkRoot))
|
||||
st, blkRoot, err = prepareForkchoiceState(ctx, 101, [32]byte{'b'}, [32]byte{'a'}, params.BeaconConfig().ZeroHash, ojc, ofc)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, c.cfg.ForkChoiceStore.InsertNode(ctx, state, blkRoot))
|
||||
require.NoError(t, c.cfg.ForkChoiceStore.InsertNode(ctx, st, blkRoot))
|
||||
|
||||
opt, err := c.IsOptimistic(ctx)
|
||||
require.NoError(t, err)
|
||||
@@ -460,12 +460,12 @@ func TestService_IsOptimistic_DoublyLinkedTree(t *testing.T) {
|
||||
ojc := ðpb.Checkpoint{Root: params.BeaconConfig().ZeroHash[:]}
|
||||
ofc := ðpb.Checkpoint{Root: params.BeaconConfig().ZeroHash[:]}
|
||||
c := &Service{cfg: &config{ForkChoiceStore: doublylinkedtree.New()}, head: &head{slot: 101, root: [32]byte{'b'}}}
|
||||
state, blkRoot, err := prepareForkchoiceState(ctx, 100, [32]byte{'a'}, [32]byte{}, params.BeaconConfig().ZeroHash, ojc, ofc)
|
||||
st, blkRoot, err := prepareForkchoiceState(ctx, 100, [32]byte{'a'}, [32]byte{}, params.BeaconConfig().ZeroHash, ojc, ofc)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, c.cfg.ForkChoiceStore.InsertNode(ctx, state, blkRoot))
|
||||
state, blkRoot, err = prepareForkchoiceState(ctx, 101, [32]byte{'b'}, [32]byte{'a'}, params.BeaconConfig().ZeroHash, ojc, ofc)
|
||||
require.NoError(t, c.cfg.ForkChoiceStore.InsertNode(ctx, st, blkRoot))
|
||||
st, blkRoot, err = prepareForkchoiceState(ctx, 101, [32]byte{'b'}, [32]byte{'a'}, params.BeaconConfig().ZeroHash, ojc, ofc)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, c.cfg.ForkChoiceStore.InsertNode(ctx, state, blkRoot))
|
||||
require.NoError(t, c.cfg.ForkChoiceStore.InsertNode(ctx, st, blkRoot))
|
||||
|
||||
opt, err := c.IsOptimistic(ctx)
|
||||
require.NoError(t, err)
|
||||
@@ -485,12 +485,12 @@ func TestService_IsOptimisticForRoot_ProtoArray(t *testing.T) {
|
||||
c := &Service{cfg: &config{ForkChoiceStore: protoarray.New()}, head: &head{slot: 101, root: [32]byte{'b'}}}
|
||||
ojc := ðpb.Checkpoint{Root: params.BeaconConfig().ZeroHash[:]}
|
||||
ofc := ðpb.Checkpoint{Root: params.BeaconConfig().ZeroHash[:]}
|
||||
state, blkRoot, err := prepareForkchoiceState(ctx, 100, [32]byte{'a'}, [32]byte{}, params.BeaconConfig().ZeroHash, ojc, ofc)
|
||||
st, blkRoot, err := prepareForkchoiceState(ctx, 100, [32]byte{'a'}, [32]byte{}, params.BeaconConfig().ZeroHash, ojc, ofc)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, c.cfg.ForkChoiceStore.InsertNode(ctx, state, blkRoot))
|
||||
state, blkRoot, err = prepareForkchoiceState(ctx, 101, [32]byte{'b'}, [32]byte{'a'}, params.BeaconConfig().ZeroHash, ojc, ofc)
|
||||
require.NoError(t, c.cfg.ForkChoiceStore.InsertNode(ctx, st, blkRoot))
|
||||
st, blkRoot, err = prepareForkchoiceState(ctx, 101, [32]byte{'b'}, [32]byte{'a'}, params.BeaconConfig().ZeroHash, ojc, ofc)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, c.cfg.ForkChoiceStore.InsertNode(ctx, state, blkRoot))
|
||||
require.NoError(t, c.cfg.ForkChoiceStore.InsertNode(ctx, st, blkRoot))
|
||||
|
||||
opt, err := c.IsOptimisticForRoot(ctx, [32]byte{'a'})
|
||||
require.NoError(t, err)
|
||||
@@ -502,12 +502,12 @@ func TestService_IsOptimisticForRoot_DoublyLinkedTree(t *testing.T) {
|
||||
c := &Service{cfg: &config{ForkChoiceStore: doublylinkedtree.New()}, head: &head{slot: 101, root: [32]byte{'b'}}}
|
||||
ojc := ðpb.Checkpoint{Root: params.BeaconConfig().ZeroHash[:]}
|
||||
ofc := ðpb.Checkpoint{Root: params.BeaconConfig().ZeroHash[:]}
|
||||
state, blkRoot, err := prepareForkchoiceState(ctx, 100, [32]byte{'a'}, [32]byte{}, params.BeaconConfig().ZeroHash, ojc, ofc)
|
||||
st, blkRoot, err := prepareForkchoiceState(ctx, 100, [32]byte{'a'}, [32]byte{}, params.BeaconConfig().ZeroHash, ojc, ofc)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, c.cfg.ForkChoiceStore.InsertNode(ctx, state, blkRoot))
|
||||
state, blkRoot, err = prepareForkchoiceState(ctx, 101, [32]byte{'b'}, [32]byte{'a'}, params.BeaconConfig().ZeroHash, ojc, ofc)
|
||||
require.NoError(t, c.cfg.ForkChoiceStore.InsertNode(ctx, st, blkRoot))
|
||||
st, blkRoot, err = prepareForkchoiceState(ctx, 101, [32]byte{'b'}, [32]byte{'a'}, params.BeaconConfig().ZeroHash, ojc, ofc)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, c.cfg.ForkChoiceStore.InsertNode(ctx, state, blkRoot))
|
||||
require.NoError(t, c.cfg.ForkChoiceStore.InsertNode(ctx, st, blkRoot))
|
||||
|
||||
opt, err := c.IsOptimisticForRoot(ctx, [32]byte{'a'})
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -966,9 +966,9 @@ func TestAncestor_CanUseForkchoice(t *testing.T) {
|
||||
beaconBlock.Block.ParentRoot = bytesutil.PadTo(b.Block.ParentRoot, 32)
|
||||
r, err := b.Block.HashTreeRoot()
|
||||
require.NoError(t, err)
|
||||
state, blkRoot, err := prepareForkchoiceState(context.Background(), b.Block.Slot, r, bytesutil.ToBytes32(b.Block.ParentRoot), params.BeaconConfig().ZeroHash, ojc, ofc)
|
||||
st, blkRoot, err := prepareForkchoiceState(context.Background(), b.Block.Slot, r, bytesutil.ToBytes32(b.Block.ParentRoot), params.BeaconConfig().ZeroHash, ojc, ofc)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, service.cfg.ForkChoiceStore.InsertNode(ctx, state, blkRoot))
|
||||
require.NoError(t, service.cfg.ForkChoiceStore.InsertNode(ctx, st, blkRoot))
|
||||
}
|
||||
|
||||
r, err := service.ancestor(context.Background(), r200[:], 150)
|
||||
@@ -1015,9 +1015,9 @@ func TestAncestor_CanUseDB(t *testing.T) {
|
||||
util.SaveBlock(t, context.Background(), beaconDB, beaconBlock)
|
||||
}
|
||||
|
||||
state, blkRoot, err := prepareForkchoiceState(context.Background(), 200, r200, r200, params.BeaconConfig().ZeroHash, ojc, ofc)
|
||||
st, blkRoot, err := prepareForkchoiceState(context.Background(), 200, r200, r200, params.BeaconConfig().ZeroHash, ojc, ofc)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, service.cfg.ForkChoiceStore.InsertNode(ctx, state, blkRoot))
|
||||
require.NoError(t, service.cfg.ForkChoiceStore.InsertNode(ctx, st, blkRoot))
|
||||
|
||||
r, err := service.ancestor(context.Background(), r200[:], 150)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/async/event"
|
||||
mock "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/cache/depositcache"
|
||||
b "github.com/prysmaticlabs/prysm/beacon-chain/core/blocks"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/blocks"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/feed"
|
||||
statefeed "github.com/prysmaticlabs/prysm/beacon-chain/core/feed/state"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
|
||||
@@ -217,9 +217,9 @@ func TestChainService_InitializeBeaconChain(t *testing.T) {
|
||||
count := uint64(10)
|
||||
deposits, _, err := util.DeterministicDepositsAndKeys(count)
|
||||
require.NoError(t, err)
|
||||
trie, _, err := util.DepositTrieFromDeposits(deposits)
|
||||
dt, _, err := util.DepositTrieFromDeposits(deposits)
|
||||
require.NoError(t, err)
|
||||
hashTreeRoot, err := trie.HashTreeRoot()
|
||||
hashTreeRoot, err := dt.HashTreeRoot()
|
||||
require.NoError(t, err)
|
||||
genState, err := transition.EmptyGenesisState()
|
||||
require.NoError(t, err)
|
||||
@@ -229,7 +229,7 @@ func TestChainService_InitializeBeaconChain(t *testing.T) {
|
||||
BlockHash: make([]byte, 32),
|
||||
})
|
||||
require.NoError(t, err)
|
||||
genState, err = b.ProcessPreGenesisDeposits(ctx, genState, deposits)
|
||||
genState, err = blocks.ProcessPreGenesisDeposits(ctx, genState, deposits)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = bc.initializeBeaconChain(ctx, time.Unix(0, 0), genState, ðpb.Eth1Data{DepositRoot: hashTreeRoot[:], BlockHash: make([]byte, 32)})
|
||||
@@ -524,10 +524,10 @@ func TestServiceStop_SaveCachedBlocks(t *testing.T) {
|
||||
cancel: cancel,
|
||||
initSyncBlocks: make(map[[32]byte]interfaces.SignedBeaconBlock),
|
||||
}
|
||||
b := util.NewBeaconBlock()
|
||||
r, err := b.Block.HashTreeRoot()
|
||||
bb := util.NewBeaconBlock()
|
||||
r, err := bb.Block.HashTreeRoot()
|
||||
require.NoError(t, err)
|
||||
wsb, err := wrapper.WrappedSignedBeaconBlock(b)
|
||||
wsb, err := wrapper.WrappedSignedBeaconBlock(bb)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, s.saveInitSyncBlock(ctx, r, wsb))
|
||||
require.NoError(t, s.Stop())
|
||||
|
||||
@@ -428,9 +428,9 @@ func TestFinalizedDeposits_DepositsCachedCorrectly(t *testing.T) {
|
||||
require.NoError(t, err, "Could not hash deposit data")
|
||||
deps = append(deps, hash[:])
|
||||
}
|
||||
trie, err := trie.GenerateTrieFromItems(deps, params.BeaconConfig().DepositContractTreeDepth)
|
||||
generatedTrie, err := trie.GenerateTrieFromItems(deps, params.BeaconConfig().DepositContractTreeDepth)
|
||||
require.NoError(t, err, "Could not generate deposit trie")
|
||||
rootA, err := trie.HashTreeRoot()
|
||||
rootA, err := generatedTrie.HashTreeRoot()
|
||||
require.NoError(t, err)
|
||||
rootB, err := cachedDeposits.Deposits.HashTreeRoot()
|
||||
require.NoError(t, err)
|
||||
@@ -490,9 +490,9 @@ func TestFinalizedDeposits_UtilizesPreviouslyCachedDeposits(t *testing.T) {
|
||||
require.NoError(t, err, "Could not hash deposit data")
|
||||
deps = append(deps, hash[:])
|
||||
}
|
||||
trie, err := trie.GenerateTrieFromItems(deps, params.BeaconConfig().DepositContractTreeDepth)
|
||||
generatedTrie, err := trie.GenerateTrieFromItems(deps, params.BeaconConfig().DepositContractTreeDepth)
|
||||
require.NoError(t, err, "Could not generate deposit trie")
|
||||
rootA, err := trie.HashTreeRoot()
|
||||
rootA, err := generatedTrie.HashTreeRoot()
|
||||
require.NoError(t, err)
|
||||
rootB, err := cachedDeposits.Deposits.HashTreeRoot()
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -109,12 +109,12 @@ func (dc *DepositCache) RemovePendingDeposit(ctx context.Context, d *ethpb.Depos
|
||||
|
||||
idx := -1
|
||||
for i, ctnr := range dc.pendingDeposits {
|
||||
hash, err := hash.HashProto(ctnr.Deposit)
|
||||
h, err := hash.HashProto(ctnr.Deposit)
|
||||
if err != nil {
|
||||
log.Errorf("Could not hash deposit %v", err)
|
||||
continue
|
||||
}
|
||||
if hash == depRoot {
|
||||
if h == depRoot {
|
||||
idx = i
|
||||
break
|
||||
}
|
||||
|
||||
8
beacon-chain/cache/sync_committee_test.go
vendored
8
beacon-chain/cache/sync_committee_test.go
vendored
@@ -161,16 +161,16 @@ func TestSyncCommitteeCache_CanUpdateAndRetrieve(t *testing.T) {
|
||||
s, _ := util.DeterministicGenesisStateAltair(t, uint64(numValidators))
|
||||
require.NoError(t, s.SetCurrentSyncCommittee(tt.currentSyncCommittee))
|
||||
require.NoError(t, s.SetNextSyncCommittee(tt.nextSyncCommittee))
|
||||
cache := cache.NewSyncCommittee()
|
||||
c := cache.NewSyncCommittee()
|
||||
r := [32]byte{'a'}
|
||||
require.NoError(t, cache.UpdatePositionsInCommittee(r, s))
|
||||
require.NoError(t, c.UpdatePositionsInCommittee(r, s))
|
||||
for key, indices := range tt.currentSyncMap {
|
||||
pos, err := cache.CurrentPeriodIndexPosition(r, key)
|
||||
pos, err := c.CurrentPeriodIndexPosition(r, key)
|
||||
require.NoError(t, err)
|
||||
require.DeepEqual(t, indices, pos)
|
||||
}
|
||||
for key, indices := range tt.nextSyncMap {
|
||||
pos, err := cache.NextPeriodIndexPosition(r, key)
|
||||
pos, err := c.NextPeriodIndexPosition(r, key)
|
||||
require.NoError(t, err)
|
||||
require.DeepEqual(t, indices, pos)
|
||||
}
|
||||
|
||||
@@ -34,8 +34,8 @@ func ProcessAttestationsNoVerifySignature(
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for idx, attestation := range body.Attestations() {
|
||||
beaconState, err = ProcessAttestationNoVerifySignature(ctx, beaconState, attestation, totalBalance)
|
||||
for idx, att := range body.Attestations() {
|
||||
beaconState, err = ProcessAttestationNoVerifySignature(ctx, beaconState, att, totalBalance)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "could not verify attestation at index %d in block", idx)
|
||||
}
|
||||
|
||||
@@ -411,21 +411,21 @@ func TestValidatorFlag_Add_ExceedsLength(t *testing.T) {
|
||||
|
||||
func TestFuzzProcessAttestationsNoVerify_10000(t *testing.T) {
|
||||
fuzzer := fuzz.NewWithSeed(0)
|
||||
state := ðpb.BeaconStateAltair{}
|
||||
st := ðpb.BeaconStateAltair{}
|
||||
b := ðpb.SignedBeaconBlockAltair{Block: ðpb.BeaconBlockAltair{}}
|
||||
for i := 0; i < 10000; i++ {
|
||||
fuzzer.Fuzz(state)
|
||||
fuzzer.Fuzz(st)
|
||||
fuzzer.Fuzz(b)
|
||||
if b.Block == nil {
|
||||
b.Block = ðpb.BeaconBlockAltair{}
|
||||
}
|
||||
s, err := stateAltair.InitializeFromProtoUnsafe(state)
|
||||
s, err := stateAltair.InitializeFromProtoUnsafe(st)
|
||||
require.NoError(t, err)
|
||||
wsb, err := wrapper.WrappedSignedBeaconBlock(b)
|
||||
require.NoError(t, err)
|
||||
r, err := altair.ProcessAttestationsNoVerifySignature(context.Background(), s, wsb)
|
||||
if err != nil && r != nil {
|
||||
t.Fatalf("return value should be nil on err. found: %v on error: %v for state: %v and block: %v", r, err, state, b)
|
||||
t.Fatalf("return value should be nil on err. found: %v on error: %v for state: %v and block: %v", r, err, s, b)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ func ProcessDeposits(
|
||||
if deposit == nil || deposit.Data == nil {
|
||||
return nil, errors.New("got a nil deposit in block")
|
||||
}
|
||||
beaconState, err = ProcessDeposit(ctx, beaconState, deposit, batchVerified)
|
||||
beaconState, err = ProcessDeposit(beaconState, deposit, batchVerified)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "could not process deposit from %#x", bytesutil.Trunc(deposit.Data.PublicKey))
|
||||
}
|
||||
@@ -34,7 +34,7 @@ func ProcessDeposits(
|
||||
}
|
||||
|
||||
// ProcessDeposit processes validator deposit for beacon state Altair.
|
||||
func ProcessDeposit(ctx context.Context, beaconState state.BeaconState, deposit *ethpb.Deposit, verifySignature bool) (state.BeaconState, error) {
|
||||
func ProcessDeposit(beaconState state.BeaconState, deposit *ethpb.Deposit, verifySignature bool) (state.BeaconState, error) {
|
||||
beaconState, isNewValidator, err := blocks.ProcessDeposit(beaconState, deposit, verifySignature)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -40,7 +40,7 @@ func TestFuzzProcessDeposit_10000(t *testing.T) {
|
||||
fuzzer.Fuzz(deposit)
|
||||
s, err := stateAltair.InitializeFromProtoUnsafe(state)
|
||||
require.NoError(t, err)
|
||||
r, err := altair.ProcessDeposit(context.Background(), s, deposit, true)
|
||||
r, err := altair.ProcessDeposit(s, deposit, true)
|
||||
if err != nil && r != nil {
|
||||
t.Fatalf("return value should be nil on err. found: %v on error: %v for state: %v and block: %v", r, err, state, deposit)
|
||||
}
|
||||
|
||||
@@ -183,7 +183,7 @@ func TestProcessDeposit_AddsNewValidatorDeposit(t *testing.T) {
|
||||
},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
newState, err := altair.ProcessDeposit(context.Background(), beaconState, dep[0], true)
|
||||
newState, err := altair.ProcessDeposit(beaconState, dep[0], true)
|
||||
require.NoError(t, err, "Process deposit failed")
|
||||
require.Equal(t, 2, len(newState.Validators()), "Expected validator list to have length 2")
|
||||
require.Equal(t, 2, len(newState.Balances()), "Expected validator balances list to have length 2")
|
||||
@@ -201,9 +201,9 @@ func TestProcessDeposit_SkipsInvalidDeposit(t *testing.T) {
|
||||
dep, _, err := util.DeterministicDepositsAndKeys(1)
|
||||
require.NoError(t, err)
|
||||
dep[0].Data.Signature = make([]byte, 96)
|
||||
trie, _, err := util.DepositTrieFromDeposits(dep)
|
||||
dt, _, err := util.DepositTrieFromDeposits(dep)
|
||||
require.NoError(t, err)
|
||||
root, err := trie.HashTreeRoot()
|
||||
root, err := dt.HashTreeRoot()
|
||||
require.NoError(t, err)
|
||||
eth1Data := ðpb.Eth1Data{
|
||||
DepositRoot: root[:],
|
||||
@@ -226,7 +226,7 @@ func TestProcessDeposit_SkipsInvalidDeposit(t *testing.T) {
|
||||
},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
newState, err := altair.ProcessDeposit(context.Background(), beaconState, dep[0], true)
|
||||
newState, err := altair.ProcessDeposit(beaconState, dep[0], true)
|
||||
require.NoError(t, err, "Expected invalid block deposit to be ignored without error")
|
||||
|
||||
if newState.Eth1DepositIndex() != 1 {
|
||||
|
||||
@@ -28,12 +28,12 @@ func TestSyncCommitteeIndices_CanGet(t *testing.T) {
|
||||
EffectiveBalance: params.BeaconConfig().MinDepositAmount,
|
||||
}
|
||||
}
|
||||
state, err := stateAltair.InitializeFromProto(ðpb.BeaconStateAltair{
|
||||
st, err := stateAltair.InitializeFromProto(ðpb.BeaconStateAltair{
|
||||
Validators: validators,
|
||||
RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector),
|
||||
})
|
||||
require.NoError(t, err)
|
||||
return state
|
||||
return st
|
||||
}
|
||||
|
||||
type args struct {
|
||||
@@ -103,27 +103,27 @@ func TestSyncCommitteeIndices_DifferentPeriods(t *testing.T) {
|
||||
EffectiveBalance: params.BeaconConfig().MinDepositAmount,
|
||||
}
|
||||
}
|
||||
state, err := stateAltair.InitializeFromProto(ðpb.BeaconStateAltair{
|
||||
st, err := stateAltair.InitializeFromProto(ðpb.BeaconStateAltair{
|
||||
Validators: validators,
|
||||
RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector),
|
||||
})
|
||||
require.NoError(t, err)
|
||||
return state
|
||||
return st
|
||||
}
|
||||
|
||||
state := getState(t, params.BeaconConfig().MaxValidatorsPerCommittee)
|
||||
got1, err := altair.NextSyncCommitteeIndices(context.Background(), state)
|
||||
st := getState(t, params.BeaconConfig().MaxValidatorsPerCommittee)
|
||||
got1, err := altair.NextSyncCommitteeIndices(context.Background(), st)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, state.SetSlot(params.BeaconConfig().SlotsPerEpoch))
|
||||
got2, err := altair.NextSyncCommitteeIndices(context.Background(), state)
|
||||
require.NoError(t, st.SetSlot(params.BeaconConfig().SlotsPerEpoch))
|
||||
got2, err := altair.NextSyncCommitteeIndices(context.Background(), st)
|
||||
require.NoError(t, err)
|
||||
require.DeepNotEqual(t, got1, got2)
|
||||
require.NoError(t, state.SetSlot(params.BeaconConfig().SlotsPerEpoch*types.Slot(params.BeaconConfig().EpochsPerSyncCommitteePeriod)))
|
||||
got2, err = altair.NextSyncCommitteeIndices(context.Background(), state)
|
||||
require.NoError(t, st.SetSlot(params.BeaconConfig().SlotsPerEpoch*types.Slot(params.BeaconConfig().EpochsPerSyncCommitteePeriod)))
|
||||
got2, err = altair.NextSyncCommitteeIndices(context.Background(), st)
|
||||
require.NoError(t, err)
|
||||
require.DeepNotEqual(t, got1, got2)
|
||||
require.NoError(t, state.SetSlot(params.BeaconConfig().SlotsPerEpoch*types.Slot(2*params.BeaconConfig().EpochsPerSyncCommitteePeriod)))
|
||||
got2, err = altair.NextSyncCommitteeIndices(context.Background(), state)
|
||||
require.NoError(t, st.SetSlot(params.BeaconConfig().SlotsPerEpoch*types.Slot(2*params.BeaconConfig().EpochsPerSyncCommitteePeriod)))
|
||||
got2, err = altair.NextSyncCommitteeIndices(context.Background(), st)
|
||||
require.NoError(t, err)
|
||||
require.DeepNotEqual(t, got1, got2)
|
||||
}
|
||||
@@ -140,12 +140,12 @@ func TestSyncCommittee_CanGet(t *testing.T) {
|
||||
PublicKey: blsKey.PublicKey().Marshal(),
|
||||
}
|
||||
}
|
||||
state, err := stateAltair.InitializeFromProto(ðpb.BeaconStateAltair{
|
||||
st, err := stateAltair.InitializeFromProto(ðpb.BeaconStateAltair{
|
||||
Validators: validators,
|
||||
RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector),
|
||||
})
|
||||
require.NoError(t, err)
|
||||
return state
|
||||
return st
|
||||
}
|
||||
|
||||
type args struct {
|
||||
@@ -260,8 +260,8 @@ func TestValidateNilSyncContribution(t *testing.T) {
|
||||
|
||||
func TestSyncSubCommitteePubkeys_CanGet(t *testing.T) {
|
||||
helpers.ClearCache()
|
||||
state := getState(t, params.BeaconConfig().MaxValidatorsPerCommittee)
|
||||
com, err := altair.NextSyncCommittee(context.Background(), state)
|
||||
st := getState(t, params.BeaconConfig().MaxValidatorsPerCommittee)
|
||||
com, err := altair.NextSyncCommittee(context.Background(), st)
|
||||
require.NoError(t, err)
|
||||
sub, err := altair.SyncSubCommitteePubkeys(com, 0)
|
||||
require.NoError(t, err)
|
||||
@@ -395,10 +395,10 @@ func getState(t *testing.T, count uint64) state.BeaconState {
|
||||
PublicKey: blsKey.PublicKey().Marshal(),
|
||||
}
|
||||
}
|
||||
state, err := stateAltair.InitializeFromProto(ðpb.BeaconStateAltair{
|
||||
st, err := stateAltair.InitializeFromProto(ðpb.BeaconStateAltair{
|
||||
Validators: validators,
|
||||
RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector),
|
||||
})
|
||||
require.NoError(t, err)
|
||||
return state
|
||||
return st
|
||||
}
|
||||
|
||||
@@ -31,8 +31,8 @@ func ProcessAttestationsNoVerifySignature(
|
||||
}
|
||||
body := b.Block().Body()
|
||||
var err error
|
||||
for idx, attestation := range body.Attestations() {
|
||||
beaconState, err = ProcessAttestationNoVerifySignature(ctx, beaconState, attestation)
|
||||
for idx, att := range body.Attestations() {
|
||||
beaconState, err = ProcessAttestationNoVerifySignature(ctx, beaconState, att)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "could not verify attestation at index %d in block", idx)
|
||||
}
|
||||
|
||||
@@ -37,8 +37,8 @@ func ProcessPreGenesisDeposits(
|
||||
|
||||
// ActivateValidatorWithEffectiveBalance updates validator's effective balance, and if it's above MaxEffectiveBalance, validator becomes active in genesis.
|
||||
func ActivateValidatorWithEffectiveBalance(beaconState state.BeaconState, deposits []*ethpb.Deposit) (state.BeaconState, error) {
|
||||
for _, deposit := range deposits {
|
||||
pubkey := deposit.Data.PublicKey
|
||||
for _, d := range deposits {
|
||||
pubkey := d.Data.PublicKey
|
||||
index, ok := beaconState.ValidatorIndexByPubkey(bytesutil.ToBytes48(pubkey))
|
||||
// In the event of the pubkey not existing, we continue processing the other
|
||||
// deposits.
|
||||
@@ -85,13 +85,13 @@ func ProcessDeposits(
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, deposit := range deposits {
|
||||
if deposit == nil || deposit.Data == nil {
|
||||
for _, d := range deposits {
|
||||
if d == nil || d.Data == nil {
|
||||
return nil, errors.New("got a nil deposit in block")
|
||||
}
|
||||
beaconState, _, err = ProcessDeposit(beaconState, deposit, batchVerified)
|
||||
beaconState, _, err = ProcessDeposit(beaconState, d, batchVerified)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "could not process deposit from %#x", bytesutil.Trunc(deposit.Data.PublicKey))
|
||||
return nil, errors.Wrapf(err, "could not process deposit from %#x", bytesutil.Trunc(d.Data.PublicKey))
|
||||
}
|
||||
}
|
||||
return beaconState, nil
|
||||
|
||||
@@ -232,9 +232,9 @@ func TestProcessDeposit_SkipsInvalidDeposit(t *testing.T) {
|
||||
dep, _, err := util.DeterministicDepositsAndKeys(1)
|
||||
require.NoError(t, err)
|
||||
dep[0].Data.Signature = make([]byte, 96)
|
||||
trie, _, err := util.DepositTrieFromDeposits(dep)
|
||||
dt, _, err := util.DepositTrieFromDeposits(dep)
|
||||
require.NoError(t, err)
|
||||
root, err := trie.HashTreeRoot()
|
||||
root, err := dt.HashTreeRoot()
|
||||
require.NoError(t, err)
|
||||
eth1Data := ðpb.Eth1Data{
|
||||
DepositRoot: root[:],
|
||||
@@ -283,15 +283,15 @@ func TestPreGenesisDeposits_SkipInvalidDeposit(t *testing.T) {
|
||||
dep, _, err := util.DeterministicDepositsAndKeys(100)
|
||||
require.NoError(t, err)
|
||||
dep[0].Data.Signature = make([]byte, 96)
|
||||
trie, _, err := util.DepositTrieFromDeposits(dep)
|
||||
dt, _, err := util.DepositTrieFromDeposits(dep)
|
||||
require.NoError(t, err)
|
||||
|
||||
for i := range dep {
|
||||
proof, err := trie.MerkleProof(i)
|
||||
proof, err := dt.MerkleProof(i)
|
||||
require.NoError(t, err)
|
||||
dep[i].Proof = proof
|
||||
}
|
||||
root, err := trie.HashTreeRoot()
|
||||
root, err := dt.HashTreeRoot()
|
||||
require.NoError(t, err)
|
||||
|
||||
eth1Data := ðpb.Eth1Data{
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package execution
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/time"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/state"
|
||||
v3 "github.com/prysmaticlabs/prysm/beacon-chain/state/v3"
|
||||
@@ -13,7 +11,7 @@ import (
|
||||
|
||||
// UpgradeToBellatrix updates inputs a generic state to return the version Bellatrix state.
|
||||
// It inserts an empty `ExecutionPayloadHeader` into the state.
|
||||
func UpgradeToBellatrix(ctx context.Context, state state.BeaconState) (state.BeaconState, error) {
|
||||
func UpgradeToBellatrix(state state.BeaconState) (state.BeaconState, error) {
|
||||
epoch := time.CurrentEpoch(state)
|
||||
|
||||
currentSyncCommittee, err := state.CurrentSyncCommittee()
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package execution_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/execution"
|
||||
@@ -16,7 +15,7 @@ import (
|
||||
func TestUpgradeToBellatrix(t *testing.T) {
|
||||
st, _ := util.DeterministicGenesisStateAltair(t, params.BeaconConfig().MaxValidatorsPerCommittee)
|
||||
preForkState := st.Copy()
|
||||
mSt, err := execution.UpgradeToBellatrix(context.Background(), st)
|
||||
mSt, err := execution.UpgradeToBellatrix(st)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Equal(t, preForkState.GenesisTime(), mSt.GenesisTime())
|
||||
|
||||
@@ -121,8 +121,8 @@ func TestCommitteeAssignments_NoProposerForSlot0(t *testing.T) {
|
||||
ClearCache()
|
||||
_, proposerIndexToSlots, err := CommitteeAssignments(context.Background(), state, 0)
|
||||
require.NoError(t, err, "Failed to determine CommitteeAssignments")
|
||||
for _, slots := range proposerIndexToSlots {
|
||||
for _, s := range slots {
|
||||
for _, ss := range proposerIndexToSlots {
|
||||
for _, s := range ss {
|
||||
assert.NotEqual(t, uint64(0), s, "No proposer should be assigned to slot 0")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,8 +96,8 @@ func ComputeShuffledIndex(index types.ValidatorIndex, indexCount uint64, seed [3
|
||||
copy(buf[:32], seed[:])
|
||||
for {
|
||||
buf[seedSize] = round
|
||||
hash := hashfunc(buf[:pivotViewSize])
|
||||
hash8 := hash[:8]
|
||||
h := hashfunc(buf[:pivotViewSize])
|
||||
hash8 := h[:8]
|
||||
hash8Int := bytesutil.FromBytes8(hash8)
|
||||
pivot := hash8Int % indexCount
|
||||
flip := (pivot + indexCount - uint64(index)) % indexCount
|
||||
|
||||
@@ -112,7 +112,7 @@ func TestSigningRoot_ComputeForkDigest(t *testing.T) {
|
||||
|
||||
func TestFuzzverifySigningRoot_10000(_ *testing.T) {
|
||||
fuzzer := fuzz.NewWithSeed(0)
|
||||
state := ðpb.BeaconState{}
|
||||
st := ðpb.BeaconState{}
|
||||
pubkey := [fieldparams.BLSPubkeyLength]byte{}
|
||||
sig := [96]byte{}
|
||||
domain := [4]byte{}
|
||||
@@ -120,17 +120,17 @@ func TestFuzzverifySigningRoot_10000(_ *testing.T) {
|
||||
var s []byte
|
||||
var d []byte
|
||||
for i := 0; i < 10000; i++ {
|
||||
fuzzer.Fuzz(state)
|
||||
fuzzer.Fuzz(st)
|
||||
fuzzer.Fuzz(&pubkey)
|
||||
fuzzer.Fuzz(&sig)
|
||||
fuzzer.Fuzz(&domain)
|
||||
fuzzer.Fuzz(state)
|
||||
fuzzer.Fuzz(st)
|
||||
fuzzer.Fuzz(&p)
|
||||
fuzzer.Fuzz(&s)
|
||||
fuzzer.Fuzz(&d)
|
||||
err := signing.VerifySigningRoot(state, pubkey[:], sig[:], domain[:])
|
||||
err := signing.VerifySigningRoot(st, pubkey[:], sig[:], domain[:])
|
||||
_ = err
|
||||
err = signing.VerifySigningRoot(state, p, s, d)
|
||||
err = signing.VerifySigningRoot(st, p, s, d)
|
||||
_ = err
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,9 +43,9 @@ func TestCurrentEpoch_OK(t *testing.T) {
|
||||
{slot: 200, epoch: 6},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
state, err := v1.InitializeFromProto(ð.BeaconState{Slot: tt.slot})
|
||||
st, err := v1.InitializeFromProto(ð.BeaconState{Slot: tt.slot})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, tt.epoch, time.CurrentEpoch(state), "ActiveCurrentEpoch(%d)", state.Slot())
|
||||
assert.Equal(t, tt.epoch, time.CurrentEpoch(st), "ActiveCurrentEpoch(%d)", st.Slot())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,9 +59,9 @@ func TestPrevEpoch_OK(t *testing.T) {
|
||||
{slot: 2 * params.BeaconConfig().SlotsPerEpoch, epoch: 1},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
state, err := v1.InitializeFromProto(ð.BeaconState{Slot: tt.slot})
|
||||
st, err := v1.InitializeFromProto(ð.BeaconState{Slot: tt.slot})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, tt.epoch, time.PrevEpoch(state), "ActivePrevEpoch(%d)", state.Slot())
|
||||
assert.Equal(t, tt.epoch, time.PrevEpoch(st), "ActivePrevEpoch(%d)", st.Slot())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,9 +77,9 @@ func TestNextEpoch_OK(t *testing.T) {
|
||||
{slot: 200, epoch: types.Epoch(200/params.BeaconConfig().SlotsPerEpoch + 1)},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
state, err := v1.InitializeFromProto(ð.BeaconState{Slot: tt.slot})
|
||||
st, err := v1.InitializeFromProto(ð.BeaconState{Slot: tt.slot})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, tt.epoch, time.NextEpoch(state), "NextEpoch(%d)", state.Slot())
|
||||
assert.Equal(t, tt.epoch, time.NextEpoch(st), "NextEpoch(%d)", st.Slot())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -54,23 +54,23 @@ import (
|
||||
// return state
|
||||
// This method differs from the spec so as to process deposits beforehand instead of the end of the function.
|
||||
func GenesisBeaconState(ctx context.Context, deposits []*ethpb.Deposit, genesisTime uint64, eth1Data *ethpb.Eth1Data) (state.BeaconState, error) {
|
||||
state, err := EmptyGenesisState()
|
||||
st, err := EmptyGenesisState()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Process initial deposits.
|
||||
state, err = helpers.UpdateGenesisEth1Data(state, deposits, eth1Data)
|
||||
st, err = helpers.UpdateGenesisEth1Data(st, deposits, eth1Data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
state, err = b.ProcessPreGenesisDeposits(ctx, state, deposits)
|
||||
st, err = b.ProcessPreGenesisDeposits(ctx, st, deposits)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not process validator deposits")
|
||||
}
|
||||
|
||||
return OptimizedGenesisBeaconState(genesisTime, state, state.Eth1Data())
|
||||
return OptimizedGenesisBeaconState(genesisTime, st, st.Eth1Data())
|
||||
}
|
||||
|
||||
// OptimizedGenesisBeaconState is used to create a state that has already processed deposits. This is to efficiently
|
||||
@@ -111,7 +111,7 @@ func OptimizedGenesisBeaconState(genesisTime uint64, preState state.BeaconState,
|
||||
return nil, errors.Wrapf(err, "could not hash tree root genesis validators %v", err)
|
||||
}
|
||||
|
||||
state := ðpb.BeaconState{
|
||||
st := ðpb.BeaconState{
|
||||
// Misc fields.
|
||||
Slot: 0,
|
||||
GenesisTime: genesisTime,
|
||||
@@ -170,18 +170,18 @@ func OptimizedGenesisBeaconState(genesisTime uint64, preState state.BeaconState,
|
||||
return nil, errors.Wrap(err, "could not hash tree root empty block body")
|
||||
}
|
||||
|
||||
state.LatestBlockHeader = ðpb.BeaconBlockHeader{
|
||||
st.LatestBlockHeader = ðpb.BeaconBlockHeader{
|
||||
ParentRoot: zeroHash,
|
||||
StateRoot: zeroHash,
|
||||
BodyRoot: bodyRoot[:],
|
||||
}
|
||||
|
||||
return v1.InitializeFromProto(state)
|
||||
return v1.InitializeFromProto(st)
|
||||
}
|
||||
|
||||
// EmptyGenesisState returns an empty beacon state object.
|
||||
func EmptyGenesisState() (state.BeaconState, error) {
|
||||
state := ðpb.BeaconState{
|
||||
st := ðpb.BeaconState{
|
||||
// Misc fields.
|
||||
Slot: 0,
|
||||
Fork: ðpb.Fork{
|
||||
@@ -203,7 +203,7 @@ func EmptyGenesisState() (state.BeaconState, error) {
|
||||
Eth1DataVotes: []*ethpb.Eth1Data{},
|
||||
Eth1DepositIndex: 0,
|
||||
}
|
||||
return v1.InitializeFromProto(state)
|
||||
return v1.InitializeFromProto(st)
|
||||
}
|
||||
|
||||
// IsValidGenesisState gets called whenever there's a deposit event,
|
||||
|
||||
@@ -279,7 +279,7 @@ func ProcessSlots(ctx context.Context, state state.BeaconState, slot types.Slot)
|
||||
}
|
||||
|
||||
if time.CanUpgradeToBellatrix(state.Slot()) {
|
||||
state, err = execution.UpgradeToBellatrix(ctx, state)
|
||||
state, err = execution.UpgradeToBellatrix(state)
|
||||
if err != nil {
|
||||
tracing.AnnotateError(span, err)
|
||||
return nil, err
|
||||
|
||||
@@ -42,7 +42,7 @@ import (
|
||||
// assert block.state_root == hash_tree_root(state)
|
||||
func ExecuteStateTransitionNoVerifyAnySig(
|
||||
ctx context.Context,
|
||||
state state.BeaconState,
|
||||
st state.BeaconState,
|
||||
signed interfaces.SignedBeaconBlock,
|
||||
) (*bls.SignatureBatch, state.BeaconState, error) {
|
||||
if ctx.Err() != nil {
|
||||
@@ -57,21 +57,21 @@ func ExecuteStateTransitionNoVerifyAnySig(
|
||||
var err error
|
||||
|
||||
interop.WriteBlockToDisk(signed, false /* Has the block failed */)
|
||||
interop.WriteStateToDisk(state)
|
||||
interop.WriteStateToDisk(st)
|
||||
|
||||
state, err = ProcessSlotsUsingNextSlotCache(ctx, state, signed.Block().ParentRoot(), signed.Block().Slot())
|
||||
st, err = ProcessSlotsUsingNextSlotCache(ctx, st, signed.Block().ParentRoot(), signed.Block().Slot())
|
||||
if err != nil {
|
||||
return nil, nil, errors.Wrap(err, "could not process slots")
|
||||
}
|
||||
|
||||
// Execute per block transition.
|
||||
set, state, err := ProcessBlockNoVerifyAnySig(ctx, state, signed)
|
||||
set, st, err := ProcessBlockNoVerifyAnySig(ctx, st, signed)
|
||||
if err != nil {
|
||||
return nil, nil, errors.Wrap(err, "could not process block")
|
||||
}
|
||||
|
||||
// State root validation.
|
||||
postStateRoot, err := state.HashTreeRoot(ctx)
|
||||
postStateRoot, err := st.HashTreeRoot(ctx)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
@@ -80,7 +80,7 @@ func ExecuteStateTransitionNoVerifyAnySig(
|
||||
postStateRoot[:], signed.Block().StateRoot())
|
||||
}
|
||||
|
||||
return set, state, nil
|
||||
return set, st, nil
|
||||
}
|
||||
|
||||
// CalculateStateRoot defines the procedure for a state transition function.
|
||||
@@ -155,7 +155,7 @@ func CalculateStateRoot(
|
||||
// process_operations(state, block.body)
|
||||
func ProcessBlockNoVerifyAnySig(
|
||||
ctx context.Context,
|
||||
state state.BeaconState,
|
||||
st state.BeaconState,
|
||||
signed interfaces.SignedBeaconBlock,
|
||||
) (*bls.SignatureBatch, state.BeaconState, error) {
|
||||
ctx, span := trace.StartSpan(ctx, "core.state.ProcessBlockNoVerifyAnySig")
|
||||
@@ -164,27 +164,27 @@ func ProcessBlockNoVerifyAnySig(
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
if state.Version() != signed.Block().Version() {
|
||||
return nil, nil, fmt.Errorf("state and block are different version. %d != %d", state.Version(), signed.Block().Version())
|
||||
if st.Version() != signed.Block().Version() {
|
||||
return nil, nil, fmt.Errorf("state and block are different version. %d != %d", st.Version(), signed.Block().Version())
|
||||
}
|
||||
|
||||
blk := signed.Block()
|
||||
state, err := ProcessBlockForStateRoot(ctx, state, signed)
|
||||
st, err := ProcessBlockForStateRoot(ctx, st, signed)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
bSet, err := b.BlockSignatureBatch(state, blk.ProposerIndex(), signed.Signature(), blk.HashTreeRoot)
|
||||
bSet, err := b.BlockSignatureBatch(st, blk.ProposerIndex(), signed.Signature(), blk.HashTreeRoot)
|
||||
if err != nil {
|
||||
tracing.AnnotateError(span, err)
|
||||
return nil, nil, errors.Wrap(err, "could not retrieve block signature set")
|
||||
}
|
||||
rSet, err := b.RandaoSignatureBatch(ctx, state, signed.Block().Body().RandaoReveal())
|
||||
rSet, err := b.RandaoSignatureBatch(ctx, st, signed.Block().Body().RandaoReveal())
|
||||
if err != nil {
|
||||
tracing.AnnotateError(span, err)
|
||||
return nil, nil, errors.Wrap(err, "could not retrieve randao signature set")
|
||||
}
|
||||
aSet, err := b.AttestationSignatureBatch(ctx, state, signed.Block().Body().Attestations())
|
||||
aSet, err := b.AttestationSignatureBatch(ctx, st, signed.Block().Body().Attestations())
|
||||
if err != nil {
|
||||
return nil, nil, errors.Wrap(err, "could not retrieve attestation signature set")
|
||||
}
|
||||
@@ -193,7 +193,7 @@ func ProcessBlockNoVerifyAnySig(
|
||||
set := bls.NewSet()
|
||||
set.Join(bSet).Join(rSet).Join(aSet)
|
||||
|
||||
return set, state, nil
|
||||
return set, st, nil
|
||||
}
|
||||
|
||||
// ProcessOperationsNoVerifyAttsSigs processes the operations in the beacon block and updates beacon state
|
||||
@@ -348,45 +348,45 @@ func ProcessBlockForStateRoot(
|
||||
// This calls altair block operations.
|
||||
func altairOperations(
|
||||
ctx context.Context,
|
||||
state state.BeaconState,
|
||||
st state.BeaconState,
|
||||
signedBeaconBlock interfaces.SignedBeaconBlock) (state.BeaconState, error) {
|
||||
state, err := b.ProcessProposerSlashings(ctx, state, signedBeaconBlock.Block().Body().ProposerSlashings(), v.SlashValidator)
|
||||
st, err := b.ProcessProposerSlashings(ctx, st, signedBeaconBlock.Block().Body().ProposerSlashings(), v.SlashValidator)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not process altair proposer slashing")
|
||||
}
|
||||
state, err = b.ProcessAttesterSlashings(ctx, state, signedBeaconBlock.Block().Body().AttesterSlashings(), v.SlashValidator)
|
||||
st, err = b.ProcessAttesterSlashings(ctx, st, signedBeaconBlock.Block().Body().AttesterSlashings(), v.SlashValidator)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not process altair attester slashing")
|
||||
}
|
||||
state, err = altair.ProcessAttestationsNoVerifySignature(ctx, state, signedBeaconBlock)
|
||||
st, err = altair.ProcessAttestationsNoVerifySignature(ctx, st, signedBeaconBlock)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not process altair attestation")
|
||||
}
|
||||
if _, err := altair.ProcessDeposits(ctx, state, signedBeaconBlock.Block().Body().Deposits()); err != nil {
|
||||
if _, err := altair.ProcessDeposits(ctx, st, signedBeaconBlock.Block().Body().Deposits()); err != nil {
|
||||
return nil, errors.Wrap(err, "could not process altair deposit")
|
||||
}
|
||||
return b.ProcessVoluntaryExits(ctx, state, signedBeaconBlock.Block().Body().VoluntaryExits())
|
||||
return b.ProcessVoluntaryExits(ctx, st, signedBeaconBlock.Block().Body().VoluntaryExits())
|
||||
}
|
||||
|
||||
// This calls phase 0 block operations.
|
||||
func phase0Operations(
|
||||
ctx context.Context,
|
||||
state state.BeaconState,
|
||||
st state.BeaconState,
|
||||
signedBeaconBlock interfaces.SignedBeaconBlock) (state.BeaconState, error) {
|
||||
state, err := b.ProcessProposerSlashings(ctx, state, signedBeaconBlock.Block().Body().ProposerSlashings(), v.SlashValidator)
|
||||
st, err := b.ProcessProposerSlashings(ctx, st, signedBeaconBlock.Block().Body().ProposerSlashings(), v.SlashValidator)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not process block proposer slashings")
|
||||
}
|
||||
state, err = b.ProcessAttesterSlashings(ctx, state, signedBeaconBlock.Block().Body().AttesterSlashings(), v.SlashValidator)
|
||||
st, err = b.ProcessAttesterSlashings(ctx, st, signedBeaconBlock.Block().Body().AttesterSlashings(), v.SlashValidator)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not process block attester slashings")
|
||||
}
|
||||
state, err = b.ProcessAttestationsNoVerifySignature(ctx, state, signedBeaconBlock)
|
||||
st, err = b.ProcessAttestationsNoVerifySignature(ctx, st, signedBeaconBlock)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not process block attestations")
|
||||
}
|
||||
if _, err := b.ProcessDeposits(ctx, state, signedBeaconBlock.Block().Body().Deposits()); err != nil {
|
||||
if _, err := b.ProcessDeposits(ctx, st, signedBeaconBlock.Block().Body().Deposits()); err != nil {
|
||||
return nil, errors.Wrap(err, "could not process deposits")
|
||||
}
|
||||
return b.ProcessVoluntaryExits(ctx, state, signedBeaconBlock.Block().Body().VoluntaryExits())
|
||||
return b.ProcessVoluntaryExits(ctx, st, signedBeaconBlock.Block().Body().VoluntaryExits())
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"github.com/pkg/errors"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/state"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/state/genesis"
|
||||
state_native "github.com/prysmaticlabs/prysm/beacon-chain/state/state-native"
|
||||
statenative "github.com/prysmaticlabs/prysm/beacon-chain/state/state-native"
|
||||
v1 "github.com/prysmaticlabs/prysm/beacon-chain/state/v1"
|
||||
v2 "github.com/prysmaticlabs/prysm/beacon-chain/state/v2"
|
||||
v3 "github.com/prysmaticlabs/prysm/beacon-chain/state/v3"
|
||||
@@ -224,7 +224,7 @@ func (s *Store) saveStatesEfficientInternal(ctx context.Context, tx *bolt.Tx, bl
|
||||
var pbState *ethpb.BeaconState
|
||||
var err error
|
||||
if features.Get().EnableNativeState {
|
||||
pbState, err = state_native.ProtobufBeaconStatePhase0(rawType)
|
||||
pbState, err = statenative.ProtobufBeaconStatePhase0(rawType)
|
||||
} else {
|
||||
pbState, err = v1.ProtobufBeaconState(rawType)
|
||||
}
|
||||
@@ -251,7 +251,7 @@ func (s *Store) saveStatesEfficientInternal(ctx context.Context, tx *bolt.Tx, bl
|
||||
var pbState *ethpb.BeaconStateAltair
|
||||
var err error
|
||||
if features.Get().EnableNativeState {
|
||||
pbState, err = state_native.ProtobufBeaconStateAltair(rawType)
|
||||
pbState, err = statenative.ProtobufBeaconStateAltair(rawType)
|
||||
} else {
|
||||
pbState, err = v2.ProtobufBeaconState(rawType)
|
||||
}
|
||||
@@ -279,7 +279,7 @@ func (s *Store) saveStatesEfficientInternal(ctx context.Context, tx *bolt.Tx, bl
|
||||
var pbState *ethpb.BeaconStateBellatrix
|
||||
var err error
|
||||
if features.Get().EnableNativeState {
|
||||
pbState, err = state_native.ProtobufBeaconStateBellatrix(rawType)
|
||||
pbState, err = statenative.ProtobufBeaconStateBellatrix(rawType)
|
||||
} else {
|
||||
pbState, err = v3.ProtobufBeaconState(rawType)
|
||||
}
|
||||
|
||||
@@ -64,15 +64,15 @@ func prepareForkchoiceState(
|
||||
func TestForkChoice_UpdateBalancesPositiveChange(t *testing.T) {
|
||||
f := setup(0, 0)
|
||||
ctx := context.Background()
|
||||
state, blkRoot, err := prepareForkchoiceState(ctx, 1, indexToHash(1), params.BeaconConfig().ZeroHash, params.BeaconConfig().ZeroHash, 0, 0)
|
||||
st, blkRoot, err := prepareForkchoiceState(ctx, 1, indexToHash(1), params.BeaconConfig().ZeroHash, params.BeaconConfig().ZeroHash, 0, 0)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, f.InsertNode(ctx, state, blkRoot))
|
||||
state, blkRoot, err = prepareForkchoiceState(ctx, 2, indexToHash(2), indexToHash(1), params.BeaconConfig().ZeroHash, 0, 0)
|
||||
require.NoError(t, f.InsertNode(ctx, st, blkRoot))
|
||||
st, blkRoot, err = prepareForkchoiceState(ctx, 2, indexToHash(2), indexToHash(1), params.BeaconConfig().ZeroHash, 0, 0)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, f.InsertNode(ctx, state, blkRoot))
|
||||
state, blkRoot, err = prepareForkchoiceState(ctx, 3, indexToHash(3), indexToHash(2), params.BeaconConfig().ZeroHash, 0, 0)
|
||||
require.NoError(t, f.InsertNode(ctx, st, blkRoot))
|
||||
st, blkRoot, err = prepareForkchoiceState(ctx, 3, indexToHash(3), indexToHash(2), params.BeaconConfig().ZeroHash, 0, 0)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, f.InsertNode(ctx, state, blkRoot))
|
||||
require.NoError(t, f.InsertNode(ctx, st, blkRoot))
|
||||
|
||||
f.votes = []Vote{
|
||||
{indexToHash(1), indexToHash(1), 0},
|
||||
@@ -92,15 +92,15 @@ func TestForkChoice_UpdateBalancesPositiveChange(t *testing.T) {
|
||||
func TestForkChoice_UpdateBalancesNegativeChange(t *testing.T) {
|
||||
f := setup(0, 0)
|
||||
ctx := context.Background()
|
||||
state, blkRoot, err := prepareForkchoiceState(ctx, 1, indexToHash(1), params.BeaconConfig().ZeroHash, params.BeaconConfig().ZeroHash, 0, 0)
|
||||
st, blkRoot, err := prepareForkchoiceState(ctx, 1, indexToHash(1), params.BeaconConfig().ZeroHash, params.BeaconConfig().ZeroHash, 0, 0)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, f.InsertNode(ctx, state, blkRoot))
|
||||
state, blkRoot, err = prepareForkchoiceState(ctx, 2, indexToHash(2), indexToHash(1), params.BeaconConfig().ZeroHash, 0, 0)
|
||||
require.NoError(t, f.InsertNode(ctx, st, blkRoot))
|
||||
st, blkRoot, err = prepareForkchoiceState(ctx, 2, indexToHash(2), indexToHash(1), params.BeaconConfig().ZeroHash, 0, 0)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, f.InsertNode(ctx, state, blkRoot))
|
||||
state, blkRoot, err = prepareForkchoiceState(ctx, 3, indexToHash(3), indexToHash(2), params.BeaconConfig().ZeroHash, 0, 0)
|
||||
require.NoError(t, f.InsertNode(ctx, st, blkRoot))
|
||||
st, blkRoot, err = prepareForkchoiceState(ctx, 3, indexToHash(3), indexToHash(2), params.BeaconConfig().ZeroHash, 0, 0)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, f.InsertNode(ctx, state, blkRoot))
|
||||
require.NoError(t, f.InsertNode(ctx, st, blkRoot))
|
||||
s := f.store
|
||||
s.nodeByRoot[indexToHash(1)].balance = 100
|
||||
s.nodeByRoot[indexToHash(2)].balance = 100
|
||||
@@ -122,15 +122,15 @@ func TestForkChoice_UpdateBalancesNegativeChange(t *testing.T) {
|
||||
func TestForkChoice_UpdateBalancesUnderflow(t *testing.T) {
|
||||
f := setup(0, 0)
|
||||
ctx := context.Background()
|
||||
state, blkRoot, err := prepareForkchoiceState(ctx, 1, indexToHash(1), params.BeaconConfig().ZeroHash, params.BeaconConfig().ZeroHash, 0, 0)
|
||||
st, blkRoot, err := prepareForkchoiceState(ctx, 1, indexToHash(1), params.BeaconConfig().ZeroHash, params.BeaconConfig().ZeroHash, 0, 0)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, f.InsertNode(ctx, state, blkRoot))
|
||||
state, blkRoot, err = prepareForkchoiceState(ctx, 2, indexToHash(2), indexToHash(1), params.BeaconConfig().ZeroHash, 0, 0)
|
||||
require.NoError(t, f.InsertNode(ctx, st, blkRoot))
|
||||
st, blkRoot, err = prepareForkchoiceState(ctx, 2, indexToHash(2), indexToHash(1), params.BeaconConfig().ZeroHash, 0, 0)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, f.InsertNode(ctx, state, blkRoot))
|
||||
state, blkRoot, err = prepareForkchoiceState(ctx, 3, indexToHash(3), indexToHash(2), params.BeaconConfig().ZeroHash, 0, 0)
|
||||
require.NoError(t, f.InsertNode(ctx, st, blkRoot))
|
||||
st, blkRoot, err = prepareForkchoiceState(ctx, 3, indexToHash(3), indexToHash(2), params.BeaconConfig().ZeroHash, 0, 0)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, f.InsertNode(ctx, state, blkRoot))
|
||||
require.NoError(t, f.InsertNode(ctx, st, blkRoot))
|
||||
s := f.store
|
||||
s.nodeByRoot[indexToHash(1)].balance = 100
|
||||
s.nodeByRoot[indexToHash(2)].balance = 100
|
||||
@@ -152,24 +152,24 @@ func TestForkChoice_UpdateBalancesUnderflow(t *testing.T) {
|
||||
func TestForkChoice_IsCanonical(t *testing.T) {
|
||||
f := setup(1, 1)
|
||||
ctx := context.Background()
|
||||
state, blkRoot, err := prepareForkchoiceState(ctx, 1, indexToHash(1), params.BeaconConfig().ZeroHash, params.BeaconConfig().ZeroHash, 1, 1)
|
||||
st, blkRoot, err := prepareForkchoiceState(ctx, 1, indexToHash(1), params.BeaconConfig().ZeroHash, params.BeaconConfig().ZeroHash, 1, 1)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, f.InsertNode(ctx, state, blkRoot))
|
||||
state, blkRoot, err = prepareForkchoiceState(ctx, 2, indexToHash(2), params.BeaconConfig().ZeroHash, params.BeaconConfig().ZeroHash, 1, 1)
|
||||
require.NoError(t, f.InsertNode(ctx, st, blkRoot))
|
||||
st, blkRoot, err = prepareForkchoiceState(ctx, 2, indexToHash(2), params.BeaconConfig().ZeroHash, params.BeaconConfig().ZeroHash, 1, 1)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, f.InsertNode(ctx, state, blkRoot))
|
||||
state, blkRoot, err = prepareForkchoiceState(ctx, 3, indexToHash(3), indexToHash(1), params.BeaconConfig().ZeroHash, 1, 1)
|
||||
require.NoError(t, f.InsertNode(ctx, st, blkRoot))
|
||||
st, blkRoot, err = prepareForkchoiceState(ctx, 3, indexToHash(3), indexToHash(1), params.BeaconConfig().ZeroHash, 1, 1)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, f.InsertNode(ctx, state, blkRoot))
|
||||
state, blkRoot, err = prepareForkchoiceState(ctx, 4, indexToHash(4), indexToHash(2), params.BeaconConfig().ZeroHash, 1, 1)
|
||||
require.NoError(t, f.InsertNode(ctx, st, blkRoot))
|
||||
st, blkRoot, err = prepareForkchoiceState(ctx, 4, indexToHash(4), indexToHash(2), params.BeaconConfig().ZeroHash, 1, 1)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, f.InsertNode(ctx, state, blkRoot))
|
||||
state, blkRoot, err = prepareForkchoiceState(ctx, 5, indexToHash(5), indexToHash(4), params.BeaconConfig().ZeroHash, 1, 1)
|
||||
require.NoError(t, f.InsertNode(ctx, st, blkRoot))
|
||||
st, blkRoot, err = prepareForkchoiceState(ctx, 5, indexToHash(5), indexToHash(4), params.BeaconConfig().ZeroHash, 1, 1)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, f.InsertNode(ctx, state, blkRoot))
|
||||
state, blkRoot, err = prepareForkchoiceState(ctx, 6, indexToHash(6), indexToHash(5), params.BeaconConfig().ZeroHash, 1, 1)
|
||||
require.NoError(t, f.InsertNode(ctx, st, blkRoot))
|
||||
st, blkRoot, err = prepareForkchoiceState(ctx, 6, indexToHash(6), indexToHash(5), params.BeaconConfig().ZeroHash, 1, 1)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, f.InsertNode(ctx, state, blkRoot))
|
||||
require.NoError(t, f.InsertNode(ctx, st, blkRoot))
|
||||
|
||||
require.Equal(t, true, f.IsCanonical(params.BeaconConfig().ZeroHash))
|
||||
require.Equal(t, false, f.IsCanonical(indexToHash(1)))
|
||||
@@ -183,24 +183,24 @@ func TestForkChoice_IsCanonical(t *testing.T) {
|
||||
func TestForkChoice_IsCanonicalReorg(t *testing.T) {
|
||||
f := setup(1, 1)
|
||||
ctx := context.Background()
|
||||
state, blkRoot, err := prepareForkchoiceState(ctx, 1, [32]byte{'1'}, params.BeaconConfig().ZeroHash, params.BeaconConfig().ZeroHash, 1, 1)
|
||||
st, blkRoot, err := prepareForkchoiceState(ctx, 1, [32]byte{'1'}, params.BeaconConfig().ZeroHash, params.BeaconConfig().ZeroHash, 1, 1)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, f.InsertNode(ctx, state, blkRoot))
|
||||
state, blkRoot, err = prepareForkchoiceState(ctx, 2, [32]byte{'2'}, params.BeaconConfig().ZeroHash, params.BeaconConfig().ZeroHash, 1, 1)
|
||||
require.NoError(t, f.InsertNode(ctx, st, blkRoot))
|
||||
st, blkRoot, err = prepareForkchoiceState(ctx, 2, [32]byte{'2'}, params.BeaconConfig().ZeroHash, params.BeaconConfig().ZeroHash, 1, 1)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, f.InsertNode(ctx, state, blkRoot))
|
||||
state, blkRoot, err = prepareForkchoiceState(ctx, 3, [32]byte{'3'}, [32]byte{'1'}, params.BeaconConfig().ZeroHash, 1, 1)
|
||||
require.NoError(t, f.InsertNode(ctx, st, blkRoot))
|
||||
st, blkRoot, err = prepareForkchoiceState(ctx, 3, [32]byte{'3'}, [32]byte{'1'}, params.BeaconConfig().ZeroHash, 1, 1)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, f.InsertNode(ctx, state, blkRoot))
|
||||
state, blkRoot, err = prepareForkchoiceState(ctx, 4, [32]byte{'4'}, [32]byte{'2'}, params.BeaconConfig().ZeroHash, 1, 1)
|
||||
require.NoError(t, f.InsertNode(ctx, st, blkRoot))
|
||||
st, blkRoot, err = prepareForkchoiceState(ctx, 4, [32]byte{'4'}, [32]byte{'2'}, params.BeaconConfig().ZeroHash, 1, 1)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, f.InsertNode(ctx, state, blkRoot))
|
||||
state, blkRoot, err = prepareForkchoiceState(ctx, 5, [32]byte{'5'}, [32]byte{'4'}, params.BeaconConfig().ZeroHash, 1, 1)
|
||||
require.NoError(t, f.InsertNode(ctx, st, blkRoot))
|
||||
st, blkRoot, err = prepareForkchoiceState(ctx, 5, [32]byte{'5'}, [32]byte{'4'}, params.BeaconConfig().ZeroHash, 1, 1)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, f.InsertNode(ctx, state, blkRoot))
|
||||
state, blkRoot, err = prepareForkchoiceState(ctx, 6, [32]byte{'6'}, [32]byte{'5'}, params.BeaconConfig().ZeroHash, 1, 1)
|
||||
require.NoError(t, f.InsertNode(ctx, st, blkRoot))
|
||||
st, blkRoot, err = prepareForkchoiceState(ctx, 6, [32]byte{'6'}, [32]byte{'5'}, params.BeaconConfig().ZeroHash, 1, 1)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, f.InsertNode(ctx, state, blkRoot))
|
||||
require.NoError(t, f.InsertNode(ctx, st, blkRoot))
|
||||
|
||||
f.store.nodesLock.Lock()
|
||||
f.store.nodeByRoot[[32]byte{'3'}].balance = 10
|
||||
@@ -231,15 +231,15 @@ func TestForkChoice_IsCanonicalReorg(t *testing.T) {
|
||||
func TestForkChoice_AncestorRoot(t *testing.T) {
|
||||
f := setup(1, 1)
|
||||
ctx := context.Background()
|
||||
state, blkRoot, err := prepareForkchoiceState(ctx, 1, indexToHash(1), params.BeaconConfig().ZeroHash, params.BeaconConfig().ZeroHash, 1, 1)
|
||||
st, blkRoot, err := prepareForkchoiceState(ctx, 1, indexToHash(1), params.BeaconConfig().ZeroHash, params.BeaconConfig().ZeroHash, 1, 1)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, f.InsertNode(ctx, state, blkRoot))
|
||||
state, blkRoot, err = prepareForkchoiceState(ctx, 2, indexToHash(2), indexToHash(1), params.BeaconConfig().ZeroHash, 1, 1)
|
||||
require.NoError(t, f.InsertNode(ctx, st, blkRoot))
|
||||
st, blkRoot, err = prepareForkchoiceState(ctx, 2, indexToHash(2), indexToHash(1), params.BeaconConfig().ZeroHash, 1, 1)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, f.InsertNode(ctx, state, blkRoot))
|
||||
state, blkRoot, err = prepareForkchoiceState(ctx, 5, indexToHash(3), indexToHash(2), params.BeaconConfig().ZeroHash, 1, 1)
|
||||
require.NoError(t, f.InsertNode(ctx, st, blkRoot))
|
||||
st, blkRoot, err = prepareForkchoiceState(ctx, 5, indexToHash(3), indexToHash(2), params.BeaconConfig().ZeroHash, 1, 1)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, f.InsertNode(ctx, state, blkRoot))
|
||||
require.NoError(t, f.InsertNode(ctx, st, blkRoot))
|
||||
f.store.treeRootNode = f.store.nodeByRoot[indexToHash(1)]
|
||||
f.store.treeRootNode.parent = nil
|
||||
|
||||
@@ -263,12 +263,12 @@ func TestForkChoice_AncestorRoot(t *testing.T) {
|
||||
func TestForkChoice_AncestorEqualSlot(t *testing.T) {
|
||||
f := setup(1, 1)
|
||||
ctx := context.Background()
|
||||
state, blkRoot, err := prepareForkchoiceState(ctx, 100, [32]byte{'1'}, params.BeaconConfig().ZeroHash, params.BeaconConfig().ZeroHash, 1, 1)
|
||||
st, blkRoot, err := prepareForkchoiceState(ctx, 100, [32]byte{'1'}, params.BeaconConfig().ZeroHash, params.BeaconConfig().ZeroHash, 1, 1)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, f.InsertNode(ctx, state, blkRoot))
|
||||
state, blkRoot, err = prepareForkchoiceState(ctx, 101, [32]byte{'3'}, [32]byte{'1'}, params.BeaconConfig().ZeroHash, 1, 1)
|
||||
require.NoError(t, f.InsertNode(ctx, st, blkRoot))
|
||||
st, blkRoot, err = prepareForkchoiceState(ctx, 101, [32]byte{'3'}, [32]byte{'1'}, params.BeaconConfig().ZeroHash, 1, 1)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, f.InsertNode(ctx, state, blkRoot))
|
||||
require.NoError(t, f.InsertNode(ctx, st, blkRoot))
|
||||
|
||||
r, err := f.AncestorRoot(ctx, [32]byte{'3'}, 100)
|
||||
require.NoError(t, err)
|
||||
@@ -278,12 +278,12 @@ func TestForkChoice_AncestorEqualSlot(t *testing.T) {
|
||||
func TestForkChoice_AncestorLowerSlot(t *testing.T) {
|
||||
f := setup(1, 1)
|
||||
ctx := context.Background()
|
||||
state, blkRoot, err := prepareForkchoiceState(ctx, 100, [32]byte{'1'}, params.BeaconConfig().ZeroHash, params.BeaconConfig().ZeroHash, 1, 1)
|
||||
st, blkRoot, err := prepareForkchoiceState(ctx, 100, [32]byte{'1'}, params.BeaconConfig().ZeroHash, params.BeaconConfig().ZeroHash, 1, 1)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, f.InsertNode(ctx, state, blkRoot))
|
||||
state, blkRoot, err = prepareForkchoiceState(ctx, 200, [32]byte{'3'}, [32]byte{'1'}, params.BeaconConfig().ZeroHash, 1, 1)
|
||||
require.NoError(t, f.InsertNode(ctx, st, blkRoot))
|
||||
st, blkRoot, err = prepareForkchoiceState(ctx, 200, [32]byte{'3'}, [32]byte{'1'}, params.BeaconConfig().ZeroHash, 1, 1)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, f.InsertNode(ctx, state, blkRoot))
|
||||
require.NoError(t, f.InsertNode(ctx, st, blkRoot))
|
||||
|
||||
r, err := f.AncestorRoot(ctx, [32]byte{'3'}, 150)
|
||||
require.NoError(t, err)
|
||||
@@ -294,20 +294,20 @@ func TestForkChoice_RemoveEquivocating(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
f := setup(1, 1)
|
||||
// Insert a block it will be head
|
||||
state, blkRoot, err := prepareForkchoiceState(ctx, 1, [32]byte{'a'}, params.BeaconConfig().ZeroHash, [32]byte{'A'}, 1, 1)
|
||||
st, blkRoot, err := prepareForkchoiceState(ctx, 1, [32]byte{'a'}, params.BeaconConfig().ZeroHash, [32]byte{'A'}, 1, 1)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, f.InsertNode(ctx, state, blkRoot))
|
||||
require.NoError(t, f.InsertNode(ctx, st, blkRoot))
|
||||
head, err := f.Head(ctx, []uint64{})
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, [32]byte{'a'}, head)
|
||||
|
||||
// Insert two extra blocks
|
||||
state, blkRoot, err = prepareForkchoiceState(ctx, 2, [32]byte{'b'}, [32]byte{'a'}, [32]byte{'B'}, 1, 1)
|
||||
st, blkRoot, err = prepareForkchoiceState(ctx, 2, [32]byte{'b'}, [32]byte{'a'}, [32]byte{'B'}, 1, 1)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, f.InsertNode(ctx, state, blkRoot))
|
||||
state, blkRoot, err = prepareForkchoiceState(ctx, 3, [32]byte{'c'}, [32]byte{'a'}, [32]byte{'C'}, 1, 1)
|
||||
require.NoError(t, f.InsertNode(ctx, st, blkRoot))
|
||||
st, blkRoot, err = prepareForkchoiceState(ctx, 3, [32]byte{'c'}, [32]byte{'a'}, [32]byte{'C'}, 1, 1)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, f.InsertNode(ctx, state, blkRoot))
|
||||
require.NoError(t, f.InsertNode(ctx, st, blkRoot))
|
||||
head, err = f.Head(ctx, []uint64{})
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, [32]byte{'c'}, head)
|
||||
@@ -372,36 +372,36 @@ func TestStore_CommonAncestor(t *testing.T) {
|
||||
// \-- c -- f
|
||||
// \-- g
|
||||
// \ -- h -- i -- j
|
||||
state, blkRoot, err := prepareForkchoiceState(ctx, 0, [32]byte{'a'}, params.BeaconConfig().ZeroHash, [32]byte{'A'}, 1, 1)
|
||||
st, blkRoot, err := prepareForkchoiceState(ctx, 0, [32]byte{'a'}, params.BeaconConfig().ZeroHash, [32]byte{'A'}, 1, 1)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, f.InsertNode(ctx, state, blkRoot))
|
||||
state, blkRoot, err = prepareForkchoiceState(ctx, 1, [32]byte{'b'}, [32]byte{'a'}, [32]byte{'B'}, 1, 1)
|
||||
require.NoError(t, f.InsertNode(ctx, st, blkRoot))
|
||||
st, blkRoot, err = prepareForkchoiceState(ctx, 1, [32]byte{'b'}, [32]byte{'a'}, [32]byte{'B'}, 1, 1)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, f.InsertNode(ctx, state, blkRoot))
|
||||
state, blkRoot, err = prepareForkchoiceState(ctx, 2, [32]byte{'c'}, [32]byte{'a'}, [32]byte{'C'}, 1, 1)
|
||||
require.NoError(t, f.InsertNode(ctx, st, blkRoot))
|
||||
st, blkRoot, err = prepareForkchoiceState(ctx, 2, [32]byte{'c'}, [32]byte{'a'}, [32]byte{'C'}, 1, 1)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, f.InsertNode(ctx, state, blkRoot))
|
||||
state, blkRoot, err = prepareForkchoiceState(ctx, 3, [32]byte{'d'}, [32]byte{'b'}, [32]byte{}, 1, 1)
|
||||
require.NoError(t, f.InsertNode(ctx, st, blkRoot))
|
||||
st, blkRoot, err = prepareForkchoiceState(ctx, 3, [32]byte{'d'}, [32]byte{'b'}, [32]byte{}, 1, 1)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, f.InsertNode(ctx, state, blkRoot))
|
||||
state, blkRoot, err = prepareForkchoiceState(ctx, 4, [32]byte{'e'}, [32]byte{'d'}, [32]byte{}, 1, 1)
|
||||
require.NoError(t, f.InsertNode(ctx, st, blkRoot))
|
||||
st, blkRoot, err = prepareForkchoiceState(ctx, 4, [32]byte{'e'}, [32]byte{'d'}, [32]byte{}, 1, 1)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, f.InsertNode(ctx, state, blkRoot))
|
||||
state, blkRoot, err = prepareForkchoiceState(ctx, 5, [32]byte{'f'}, [32]byte{'c'}, [32]byte{}, 1, 1)
|
||||
require.NoError(t, f.InsertNode(ctx, st, blkRoot))
|
||||
st, blkRoot, err = prepareForkchoiceState(ctx, 5, [32]byte{'f'}, [32]byte{'c'}, [32]byte{}, 1, 1)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, f.InsertNode(ctx, state, blkRoot))
|
||||
state, blkRoot, err = prepareForkchoiceState(ctx, 6, [32]byte{'g'}, [32]byte{'c'}, [32]byte{}, 1, 1)
|
||||
require.NoError(t, f.InsertNode(ctx, st, blkRoot))
|
||||
st, blkRoot, err = prepareForkchoiceState(ctx, 6, [32]byte{'g'}, [32]byte{'c'}, [32]byte{}, 1, 1)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, f.InsertNode(ctx, state, blkRoot))
|
||||
state, blkRoot, err = prepareForkchoiceState(ctx, 7, [32]byte{'h'}, [32]byte{'c'}, [32]byte{}, 1, 1)
|
||||
require.NoError(t, f.InsertNode(ctx, st, blkRoot))
|
||||
st, blkRoot, err = prepareForkchoiceState(ctx, 7, [32]byte{'h'}, [32]byte{'c'}, [32]byte{}, 1, 1)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, f.InsertNode(ctx, state, blkRoot))
|
||||
state, blkRoot, err = prepareForkchoiceState(ctx, 8, [32]byte{'i'}, [32]byte{'h'}, [32]byte{}, 1, 1)
|
||||
require.NoError(t, f.InsertNode(ctx, st, blkRoot))
|
||||
st, blkRoot, err = prepareForkchoiceState(ctx, 8, [32]byte{'i'}, [32]byte{'h'}, [32]byte{}, 1, 1)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, f.InsertNode(ctx, state, blkRoot))
|
||||
state, blkRoot, err = prepareForkchoiceState(ctx, 9, [32]byte{'j'}, [32]byte{'i'}, [32]byte{}, 1, 1)
|
||||
require.NoError(t, f.InsertNode(ctx, st, blkRoot))
|
||||
st, blkRoot, err = prepareForkchoiceState(ctx, 9, [32]byte{'j'}, [32]byte{'i'}, [32]byte{}, 1, 1)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, f.InsertNode(ctx, state, blkRoot))
|
||||
require.NoError(t, f.InsertNode(ctx, st, blkRoot))
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
@@ -480,18 +480,18 @@ func TestStore_CommonAncestor(t *testing.T) {
|
||||
|
||||
// a -- b -- c -- d
|
||||
f = setup(0, 0)
|
||||
state, blkRoot, err = prepareForkchoiceState(ctx, 0, [32]byte{'a'}, params.BeaconConfig().ZeroHash, [32]byte{'A'}, 1, 1)
|
||||
st, blkRoot, err = prepareForkchoiceState(ctx, 0, [32]byte{'a'}, params.BeaconConfig().ZeroHash, [32]byte{'A'}, 1, 1)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, f.InsertNode(ctx, state, blkRoot))
|
||||
state, blkRoot, err = prepareForkchoiceState(ctx, 1, [32]byte{'b'}, [32]byte{'a'}, [32]byte{'B'}, 1, 1)
|
||||
require.NoError(t, f.InsertNode(ctx, st, blkRoot))
|
||||
st, blkRoot, err = prepareForkchoiceState(ctx, 1, [32]byte{'b'}, [32]byte{'a'}, [32]byte{'B'}, 1, 1)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, f.InsertNode(ctx, state, blkRoot))
|
||||
state, blkRoot, err = prepareForkchoiceState(ctx, 2, [32]byte{'c'}, [32]byte{'b'}, [32]byte{'C'}, 1, 1)
|
||||
require.NoError(t, f.InsertNode(ctx, st, blkRoot))
|
||||
st, blkRoot, err = prepareForkchoiceState(ctx, 2, [32]byte{'c'}, [32]byte{'b'}, [32]byte{'C'}, 1, 1)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, f.InsertNode(ctx, state, blkRoot))
|
||||
state, blkRoot, err = prepareForkchoiceState(ctx, 3, [32]byte{'d'}, [32]byte{'c'}, [32]byte{}, 1, 1)
|
||||
require.NoError(t, f.InsertNode(ctx, st, blkRoot))
|
||||
st, blkRoot, err = prepareForkchoiceState(ctx, 3, [32]byte{'d'}, [32]byte{'c'}, [32]byte{}, 1, 1)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, f.InsertNode(ctx, state, blkRoot))
|
||||
require.NoError(t, f.InsertNode(ctx, st, blkRoot))
|
||||
tests = []struct {
|
||||
name string
|
||||
r1 [32]byte
|
||||
@@ -696,26 +696,26 @@ func TestForkChoice_UpdateCheckpoints(t *testing.T) {
|
||||
fcs.store.bestJustifiedCheckpoint = tt.bestJustified
|
||||
fcs.store.genesisTime = uint64(time.Now().Unix()) - uint64(tt.currentSlot)*params.BeaconConfig().SecondsPerSlot
|
||||
|
||||
state, blkRoot, err := prepareForkchoiceState(ctx, 32, [32]byte{'f'},
|
||||
st, blkRoot, err := prepareForkchoiceState(ctx, 32, [32]byte{'f'},
|
||||
[32]byte{}, [32]byte{}, tt.finalized.Epoch, tt.finalized.Epoch)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, fcs.InsertNode(ctx, state, blkRoot))
|
||||
state, blkRoot, err = prepareForkchoiceState(ctx, 64, [32]byte{'j'},
|
||||
require.NoError(t, fcs.InsertNode(ctx, st, blkRoot))
|
||||
st, blkRoot, err = prepareForkchoiceState(ctx, 64, [32]byte{'j'},
|
||||
[32]byte{'f'}, [32]byte{}, tt.justified.Epoch, tt.finalized.Epoch)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, fcs.InsertNode(ctx, state, blkRoot))
|
||||
state, blkRoot, err = prepareForkchoiceState(ctx, 96, [32]byte{'b'},
|
||||
require.NoError(t, fcs.InsertNode(ctx, st, blkRoot))
|
||||
st, blkRoot, err = prepareForkchoiceState(ctx, 96, [32]byte{'b'},
|
||||
[32]byte{'j'}, [32]byte{}, tt.newJustified.Epoch, tt.newFinalized.Epoch)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, fcs.InsertNode(ctx, state, blkRoot))
|
||||
state, blkRoot, err = prepareForkchoiceState(ctx, 96, [32]byte{'c'},
|
||||
require.NoError(t, fcs.InsertNode(ctx, st, blkRoot))
|
||||
st, blkRoot, err = prepareForkchoiceState(ctx, 96, [32]byte{'c'},
|
||||
[32]byte{'f'}, [32]byte{}, tt.newJustified.Epoch, tt.newFinalized.Epoch)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, fcs.InsertNode(ctx, state, blkRoot))
|
||||
state, blkRoot, err = prepareForkchoiceState(ctx, 65, [32]byte{'h'},
|
||||
require.NoError(t, fcs.InsertNode(ctx, st, blkRoot))
|
||||
st, blkRoot, err = prepareForkchoiceState(ctx, 65, [32]byte{'h'},
|
||||
[32]byte{'f'}, [32]byte{}, tt.newFinalized.Epoch, tt.newFinalized.Epoch)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, fcs.InsertNode(ctx, state, blkRoot))
|
||||
require.NoError(t, fcs.InsertNode(ctx, st, blkRoot))
|
||||
// restart justifications cause insertion messed it up
|
||||
fcs.store.justifiedCheckpoint = tt.justified
|
||||
fcs.store.finalizedCheckpoint = tt.finalized
|
||||
|
||||
@@ -35,7 +35,7 @@ func TestPruneInvalid(t *testing.T) {
|
||||
[32]byte{'b'},
|
||||
[32]byte{'B'},
|
||||
12,
|
||||
[][32]byte{[32]byte{'j'}},
|
||||
[][32]byte{{'j'}},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
@@ -43,8 +43,8 @@ func TestPruneInvalid(t *testing.T) {
|
||||
[32]byte{'b'},
|
||||
[32]byte{'B'},
|
||||
4,
|
||||
[][32]byte{[32]byte{'f'}, [32]byte{'e'}, [32]byte{'i'}, [32]byte{'h'}, [32]byte{'l'},
|
||||
[32]byte{'k'}, [32]byte{'g'}, [32]byte{'d'}, [32]byte{'c'}},
|
||||
[][32]byte{{'f'}, {'e'}, {'i'}, {'h'}, {'l'},
|
||||
{'k'}, {'g'}, {'d'}, {'c'}},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
@@ -52,7 +52,7 @@ func TestPruneInvalid(t *testing.T) {
|
||||
[32]byte{'h'},
|
||||
[32]byte{'H'},
|
||||
12,
|
||||
[][32]byte{[32]byte{'i'}},
|
||||
[][32]byte{{'i'}},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
@@ -60,7 +60,7 @@ func TestPruneInvalid(t *testing.T) {
|
||||
[32]byte{'g'},
|
||||
[32]byte{'G'},
|
||||
11,
|
||||
[][32]byte{[32]byte{'i'}, [32]byte{'h'}},
|
||||
[][32]byte{{'i'}, {'h'}},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
@@ -68,7 +68,7 @@ func TestPruneInvalid(t *testing.T) {
|
||||
[32]byte{'d'},
|
||||
[32]byte{'D'},
|
||||
8,
|
||||
[][32]byte{[32]byte{'i'}, [32]byte{'h'}, [32]byte{'l'}, [32]byte{'k'}, [32]byte{'g'}},
|
||||
[][32]byte{{'i'}, {'h'}, {'l'}, {'k'}, {'g'}},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
@@ -76,7 +76,7 @@ func TestPruneInvalid(t *testing.T) {
|
||||
[32]byte{'h'},
|
||||
[32]byte{'D'},
|
||||
8,
|
||||
[][32]byte{[32]byte{'i'}, [32]byte{'h'}, [32]byte{'l'}, [32]byte{'k'}, [32]byte{'g'}},
|
||||
[][32]byte{{'i'}, {'h'}, {'l'}, {'k'}, {'g'}},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
@@ -84,7 +84,7 @@ func TestPruneInvalid(t *testing.T) {
|
||||
[32]byte{'e'},
|
||||
[32]byte{'D'},
|
||||
11,
|
||||
[][32]byte{[32]byte{'f'}, [32]byte{'e'}},
|
||||
[][32]byte{{'f'}, {'e'}},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
@@ -93,14 +93,14 @@ func TestPruneInvalid(t *testing.T) {
|
||||
[32]byte{'C'},
|
||||
5,
|
||||
[][32]byte{
|
||||
[32]byte{'f'},
|
||||
[32]byte{'e'},
|
||||
[32]byte{'i'},
|
||||
[32]byte{'h'},
|
||||
[32]byte{'l'},
|
||||
[32]byte{'k'},
|
||||
[32]byte{'g'},
|
||||
[32]byte{'d'},
|
||||
{'f'},
|
||||
{'e'},
|
||||
{'i'},
|
||||
{'h'},
|
||||
{'l'},
|
||||
{'k'},
|
||||
{'g'},
|
||||
{'d'},
|
||||
},
|
||||
nil,
|
||||
},
|
||||
@@ -109,7 +109,7 @@ func TestPruneInvalid(t *testing.T) {
|
||||
[32]byte{'d'},
|
||||
[32]byte{'E'},
|
||||
8,
|
||||
[][32]byte{[32]byte{'i'}, [32]byte{'h'}, [32]byte{'l'}, [32]byte{'k'}, [32]byte{'g'}},
|
||||
[][32]byte{{'i'}, {'h'}, {'l'}, {'k'}, {'g'}},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
@@ -117,7 +117,7 @@ func TestPruneInvalid(t *testing.T) {
|
||||
[32]byte{'j'},
|
||||
[32]byte{'B'},
|
||||
12,
|
||||
[][32]byte{[32]byte{'j'}},
|
||||
[][32]byte{{'j'}},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
@@ -141,7 +141,7 @@ func TestPruneInvalid(t *testing.T) {
|
||||
[32]byte{'h'},
|
||||
[32]byte{'D'},
|
||||
8,
|
||||
[][32]byte{[32]byte{'i'}, [32]byte{'h'}, [32]byte{'l'}, [32]byte{'k'}, [32]byte{'g'}},
|
||||
[][32]byte{{'i'}, {'h'}, {'l'}, {'k'}, {'g'}},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
@@ -149,7 +149,7 @@ func TestPruneInvalid(t *testing.T) {
|
||||
[32]byte{'h'},
|
||||
[32]byte{'D'},
|
||||
8,
|
||||
[][32]byte{[32]byte{'i'}, [32]byte{'h'}, [32]byte{'l'}, [32]byte{'k'}, [32]byte{'g'}},
|
||||
[][32]byte{{'i'}, {'h'}, {'l'}, {'k'}, {'g'}},
|
||||
nil,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -74,15 +74,15 @@ func TestFFGUpdates_OneBranch(t *testing.T) {
|
||||
// 2 <- justified: 1, finalized: 0
|
||||
// |
|
||||
// 3 <- justified: 2, finalized: 1
|
||||
state, blkRoot, err := prepareForkchoiceState(context.Background(), 1, indexToHash(1), params.BeaconConfig().ZeroHash, params.BeaconConfig().ZeroHash, 0, 0)
|
||||
st, blkRoot, err := prepareForkchoiceState(context.Background(), 1, indexToHash(1), params.BeaconConfig().ZeroHash, params.BeaconConfig().ZeroHash, 0, 0)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, f.InsertNode(ctx, state, blkRoot))
|
||||
state, blkRoot, err = prepareForkchoiceState(context.Background(), 2, indexToHash(2), indexToHash(1), params.BeaconConfig().ZeroHash, 1, 0)
|
||||
require.NoError(t, f.InsertNode(ctx, st, blkRoot))
|
||||
st, blkRoot, err = prepareForkchoiceState(context.Background(), 2, indexToHash(2), indexToHash(1), params.BeaconConfig().ZeroHash, 1, 0)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, f.InsertNode(ctx, state, blkRoot))
|
||||
state, blkRoot, err = prepareForkchoiceState(context.Background(), 3, indexToHash(3), indexToHash(2), params.BeaconConfig().ZeroHash, 2, 1)
|
||||
require.NoError(t, f.InsertNode(ctx, st, blkRoot))
|
||||
st, blkRoot, err = prepareForkchoiceState(context.Background(), 3, indexToHash(3), indexToHash(2), params.BeaconConfig().ZeroHash, 2, 1)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, f.InsertNode(ctx, state, blkRoot))
|
||||
require.NoError(t, f.InsertNode(ctx, st, blkRoot))
|
||||
|
||||
// With starting justified epoch at 0, the head should be 3:
|
||||
// 0 <- start
|
||||
@@ -146,37 +146,37 @@ func TestFFGUpdates_TwoBranches(t *testing.T) {
|
||||
// | |
|
||||
// justified: 2, finalized: 0 -> 9 10 <- justified: 2, finalized: 0
|
||||
// Left branch.
|
||||
state, blkRoot, err := prepareForkchoiceState(context.Background(), 1, indexToHash(1), params.BeaconConfig().ZeroHash, params.BeaconConfig().ZeroHash, 0, 0)
|
||||
st, blkRoot, err := prepareForkchoiceState(context.Background(), 1, indexToHash(1), params.BeaconConfig().ZeroHash, params.BeaconConfig().ZeroHash, 0, 0)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, f.InsertNode(ctx, state, blkRoot))
|
||||
state, blkRoot, err = prepareForkchoiceState(context.Background(), 2, indexToHash(3), indexToHash(1), params.BeaconConfig().ZeroHash, 1, 0)
|
||||
require.NoError(t, f.InsertNode(ctx, st, blkRoot))
|
||||
st, blkRoot, err = prepareForkchoiceState(context.Background(), 2, indexToHash(3), indexToHash(1), params.BeaconConfig().ZeroHash, 1, 0)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, f.InsertNode(ctx, state, blkRoot))
|
||||
state, blkRoot, err = prepareForkchoiceState(context.Background(), 3, indexToHash(5), indexToHash(3), params.BeaconConfig().ZeroHash, 1, 0)
|
||||
require.NoError(t, f.InsertNode(ctx, st, blkRoot))
|
||||
st, blkRoot, err = prepareForkchoiceState(context.Background(), 3, indexToHash(5), indexToHash(3), params.BeaconConfig().ZeroHash, 1, 0)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, f.InsertNode(ctx, state, blkRoot))
|
||||
state, blkRoot, err = prepareForkchoiceState(context.Background(), 4, indexToHash(7), indexToHash(5), params.BeaconConfig().ZeroHash, 1, 0)
|
||||
require.NoError(t, f.InsertNode(ctx, st, blkRoot))
|
||||
st, blkRoot, err = prepareForkchoiceState(context.Background(), 4, indexToHash(7), indexToHash(5), params.BeaconConfig().ZeroHash, 1, 0)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, f.InsertNode(ctx, state, blkRoot))
|
||||
state, blkRoot, err = prepareForkchoiceState(context.Background(), 4, indexToHash(9), indexToHash(7), params.BeaconConfig().ZeroHash, 2, 0)
|
||||
require.NoError(t, f.InsertNode(ctx, st, blkRoot))
|
||||
st, blkRoot, err = prepareForkchoiceState(context.Background(), 4, indexToHash(9), indexToHash(7), params.BeaconConfig().ZeroHash, 2, 0)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, f.InsertNode(ctx, state, blkRoot))
|
||||
require.NoError(t, f.InsertNode(ctx, st, blkRoot))
|
||||
// Right branch.
|
||||
state, blkRoot, err = prepareForkchoiceState(context.Background(), 1, indexToHash(2), params.BeaconConfig().ZeroHash, params.BeaconConfig().ZeroHash, 0, 0)
|
||||
st, blkRoot, err = prepareForkchoiceState(context.Background(), 1, indexToHash(2), params.BeaconConfig().ZeroHash, params.BeaconConfig().ZeroHash, 0, 0)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, f.InsertNode(ctx, state, blkRoot))
|
||||
state, blkRoot, err = prepareForkchoiceState(context.Background(), 2, indexToHash(4), indexToHash(2), params.BeaconConfig().ZeroHash, 0, 0)
|
||||
require.NoError(t, f.InsertNode(ctx, st, blkRoot))
|
||||
st, blkRoot, err = prepareForkchoiceState(context.Background(), 2, indexToHash(4), indexToHash(2), params.BeaconConfig().ZeroHash, 0, 0)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, f.InsertNode(ctx, state, blkRoot))
|
||||
state, blkRoot, err = prepareForkchoiceState(context.Background(), 3, indexToHash(6), indexToHash(4), params.BeaconConfig().ZeroHash, 0, 0)
|
||||
require.NoError(t, f.InsertNode(ctx, st, blkRoot))
|
||||
st, blkRoot, err = prepareForkchoiceState(context.Background(), 3, indexToHash(6), indexToHash(4), params.BeaconConfig().ZeroHash, 0, 0)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, f.InsertNode(ctx, state, blkRoot))
|
||||
state, blkRoot, err = prepareForkchoiceState(context.Background(), 4, indexToHash(8), indexToHash(6), params.BeaconConfig().ZeroHash, 1, 0)
|
||||
require.NoError(t, f.InsertNode(ctx, st, blkRoot))
|
||||
st, blkRoot, err = prepareForkchoiceState(context.Background(), 4, indexToHash(8), indexToHash(6), params.BeaconConfig().ZeroHash, 1, 0)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, f.InsertNode(ctx, state, blkRoot))
|
||||
state, blkRoot, err = prepareForkchoiceState(context.Background(), 4, indexToHash(10), indexToHash(8), params.BeaconConfig().ZeroHash, 2, 0)
|
||||
require.NoError(t, f.InsertNode(ctx, st, blkRoot))
|
||||
st, blkRoot, err = prepareForkchoiceState(context.Background(), 4, indexToHash(10), indexToHash(8), params.BeaconConfig().ZeroHash, 2, 0)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, f.InsertNode(ctx, state, blkRoot))
|
||||
require.NoError(t, f.InsertNode(ctx, st, blkRoot))
|
||||
|
||||
// With start at 0, the head should be 10:
|
||||
// 0 <-- start
|
||||
|
||||
@@ -227,7 +227,7 @@ func TestSetOptimisticToInvalid(t *testing.T) {
|
||||
3,
|
||||
12,
|
||||
8,
|
||||
[][32]byte{[32]byte{'j'}},
|
||||
[][32]byte{{'j'}},
|
||||
},
|
||||
{
|
||||
"Remove tip, parent was optimistic",
|
||||
@@ -237,7 +237,7 @@ func TestSetOptimisticToInvalid(t *testing.T) {
|
||||
NonExistentNode,
|
||||
NonExistentNode,
|
||||
1,
|
||||
[][32]byte{[32]byte{'i'}},
|
||||
[][32]byte{{'i'}},
|
||||
},
|
||||
{
|
||||
"Remove tip, lvh is inner and valid",
|
||||
@@ -247,7 +247,7 @@ func TestSetOptimisticToInvalid(t *testing.T) {
|
||||
6,
|
||||
8,
|
||||
3,
|
||||
[][32]byte{[32]byte{'g'}, [32]byte{'h'}, [32]byte{'k'}, [32]byte{'i'}, [32]byte{'l'}},
|
||||
[][32]byte{{'g'}, {'h'}, {'k'}, {'i'}, {'l'}},
|
||||
},
|
||||
{
|
||||
"Remove inner, lvh is inner and optimistic",
|
||||
@@ -257,7 +257,7 @@ func TestSetOptimisticToInvalid(t *testing.T) {
|
||||
10,
|
||||
12,
|
||||
2,
|
||||
[][32]byte{[32]byte{'h'}, [32]byte{'i'}},
|
||||
[][32]byte{{'h'}, {'i'}},
|
||||
},
|
||||
{
|
||||
"Remove tip, lvh is inner and optimistic",
|
||||
@@ -267,7 +267,7 @@ func TestSetOptimisticToInvalid(t *testing.T) {
|
||||
9,
|
||||
11,
|
||||
2,
|
||||
[][32]byte{[32]byte{'k'}, [32]byte{'l'}},
|
||||
[][32]byte{{'k'}, {'l'}},
|
||||
},
|
||||
{
|
||||
"Remove tip, lvh is not an ancestor",
|
||||
@@ -277,7 +277,7 @@ func TestSetOptimisticToInvalid(t *testing.T) {
|
||||
5,
|
||||
12,
|
||||
7,
|
||||
[][32]byte{[32]byte{'j'}},
|
||||
[][32]byte{{'j'}},
|
||||
},
|
||||
{
|
||||
"Remove inner, lvh is not an ancestor",
|
||||
@@ -287,7 +287,7 @@ func TestSetOptimisticToInvalid(t *testing.T) {
|
||||
NonExistentNode,
|
||||
NonExistentNode,
|
||||
1,
|
||||
[][32]byte{[32]byte{'g'}, [32]byte{'h'}, [32]byte{'k'}, [32]byte{'i'}, [32]byte{'l'}},
|
||||
[][32]byte{{'g'}, {'h'}, {'k'}, {'i'}, {'l'}},
|
||||
},
|
||||
{
|
||||
"Remove not inserted, parent was invalid",
|
||||
@@ -297,7 +297,7 @@ func TestSetOptimisticToInvalid(t *testing.T) {
|
||||
3,
|
||||
12,
|
||||
8,
|
||||
[][32]byte{[32]byte{'j'}},
|
||||
[][32]byte{{'j'}},
|
||||
},
|
||||
{
|
||||
"Remove not inserted, parent was valid",
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
package protoarray
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
forkchoicetypes "github.com/prysmaticlabs/prysm/beacon-chain/forkchoice/types"
|
||||
"github.com/prysmaticlabs/prysm/config/params"
|
||||
|
||||
@@ -57,8 +57,8 @@ func (s *Service) processAttestations(ctx context.Context, state state.BeaconSta
|
||||
if blk == nil || blk.Body() == nil {
|
||||
return
|
||||
}
|
||||
for _, attestation := range blk.Body().Attestations() {
|
||||
s.processIncludedAttestation(ctx, state, attestation)
|
||||
for _, att := range blk.Body().Attestations() {
|
||||
s.processIncludedAttestation(ctx, state, att)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -165,13 +165,13 @@ func (s *Service) processUnaggregatedAttestation(ctx context.Context, att *ethpb
|
||||
s.RLock()
|
||||
defer s.RUnlock()
|
||||
root := bytesutil.ToBytes32(att.Data.BeaconBlockRoot)
|
||||
state := s.config.StateGen.StateByRootIfCachedNoCopy(root)
|
||||
if state == nil {
|
||||
st := s.config.StateGen.StateByRootIfCachedNoCopy(root)
|
||||
if st == nil {
|
||||
log.WithField("BeaconBlockRoot", fmt.Sprintf("%#x", bytesutil.Trunc(root[:]))).Debug(
|
||||
"Skipping unaggregated attestation due to state not found in cache")
|
||||
return
|
||||
}
|
||||
attestingIndices, err := attestingIndices(ctx, state, att)
|
||||
attestingIndices, err := attestingIndices(ctx, st, att)
|
||||
if err != nil {
|
||||
log.WithError(err).Error("Could not get attesting indices")
|
||||
return
|
||||
@@ -207,13 +207,13 @@ func (s *Service) processAggregatedAttestation(ctx context.Context, att *ethpb.A
|
||||
|
||||
var root [32]byte
|
||||
copy(root[:], att.Aggregate.Data.BeaconBlockRoot)
|
||||
state := s.config.StateGen.StateByRootIfCachedNoCopy(root)
|
||||
if state == nil {
|
||||
st := s.config.StateGen.StateByRootIfCachedNoCopy(root)
|
||||
if st == nil {
|
||||
log.WithField("BeaconBlockRoot", fmt.Sprintf("%#x", bytesutil.Trunc(root[:]))).Debug(
|
||||
"Skipping aggregated attestation due to state not found in cache")
|
||||
return
|
||||
}
|
||||
attestingIndices, err := attestingIndices(ctx, state, att.Aggregate)
|
||||
attestingIndices, err := attestingIndices(ctx, st, att.Aggregate)
|
||||
if err != nil {
|
||||
log.WithError(err).Error("Could not get attesting indices")
|
||||
return
|
||||
|
||||
@@ -37,8 +37,8 @@ func (s *Service) processBlock(ctx context.Context, b interfaces.SignedBeaconBlo
|
||||
log.WithError(err).Error("Could not compute block's hash tree root")
|
||||
return
|
||||
}
|
||||
state := s.config.StateGen.StateByRootIfCachedNoCopy(root)
|
||||
if state == nil {
|
||||
st := s.config.StateGen.StateByRootIfCachedNoCopy(root)
|
||||
if st == nil {
|
||||
log.WithField("BeaconBlockRoot", fmt.Sprintf("%#x", bytesutil.Trunc(root[:]))).Debug(
|
||||
"Skipping block collection due to state not found in cache")
|
||||
return
|
||||
@@ -51,12 +51,12 @@ func (s *Service) processBlock(ctx context.Context, b interfaces.SignedBeaconBlo
|
||||
|
||||
if currEpoch != lastSyncedEpoch &&
|
||||
slots.SyncCommitteePeriod(currEpoch) == slots.SyncCommitteePeriod(lastSyncedEpoch) {
|
||||
s.updateSyncCommitteeTrackedVals(state)
|
||||
s.updateSyncCommitteeTrackedVals(st)
|
||||
}
|
||||
|
||||
s.processSyncAggregate(state, blk)
|
||||
s.processProposedBlock(state, root, blk)
|
||||
s.processAttestations(ctx, state, blk)
|
||||
s.processSyncAggregate(st, blk)
|
||||
s.processProposedBlock(st, root, blk)
|
||||
s.processAttestations(ctx, st, blk)
|
||||
|
||||
if blk.Slot()%(AggregateReportingPeriod*params.BeaconConfig().SlotsPerEpoch) == 0 {
|
||||
s.logAggregatedPerformance()
|
||||
|
||||
@@ -135,24 +135,24 @@ func (s *Service) run(stateChannel chan *feed.Event, stateSub event.Subscription
|
||||
log.WithError(err)
|
||||
return
|
||||
}
|
||||
state, err := s.config.HeadFetcher.HeadState(s.ctx)
|
||||
st, err := s.config.HeadFetcher.HeadState(s.ctx)
|
||||
if err != nil {
|
||||
log.WithError(err).Error("Could not get head state")
|
||||
return
|
||||
}
|
||||
if state == nil {
|
||||
if st == nil {
|
||||
log.Error("Head state is nil")
|
||||
return
|
||||
}
|
||||
|
||||
epoch := slots.ToEpoch(state.Slot())
|
||||
epoch := slots.ToEpoch(st.Slot())
|
||||
log.WithField("Epoch", epoch).Info("Synced to head epoch, starting reporting performance")
|
||||
|
||||
s.Lock()
|
||||
s.initializePerformanceStructures(state, epoch)
|
||||
s.initializePerformanceStructures(st, epoch)
|
||||
s.Unlock()
|
||||
|
||||
s.updateSyncCommitteeTrackedVals(state)
|
||||
s.updateSyncCommitteeTrackedVals(st)
|
||||
|
||||
s.Lock()
|
||||
s.isLogging = true
|
||||
@@ -200,9 +200,9 @@ func (s *Service) Stop() error {
|
||||
func (s *Service) waitForSync(stateChannel chan *feed.Event, stateSub event.Subscription) error {
|
||||
for {
|
||||
select {
|
||||
case event := <-stateChannel:
|
||||
if event.Type == statefeed.Synced {
|
||||
_, ok := event.Data.(*statefeed.SyncedData)
|
||||
case e := <-stateChannel:
|
||||
if e.Type == statefeed.Synced {
|
||||
_, ok := e.Data.(*statefeed.SyncedData)
|
||||
if !ok {
|
||||
return errNotSyncedData
|
||||
}
|
||||
@@ -231,9 +231,9 @@ func (s *Service) monitorRoutine(stateChannel chan *feed.Event, stateSub event.S
|
||||
|
||||
for {
|
||||
select {
|
||||
case event := <-stateChannel:
|
||||
if event.Type == statefeed.BlockProcessed {
|
||||
data, ok := event.Data.(*statefeed.BlockProcessedData)
|
||||
case e := <-stateChannel:
|
||||
if e.Type == statefeed.BlockProcessed {
|
||||
data, ok := e.Data.(*statefeed.BlockProcessedData)
|
||||
if !ok {
|
||||
log.Error("Event feed data is not of type *statefeed.BlockProcessedData")
|
||||
} else if data.Verified {
|
||||
@@ -241,31 +241,31 @@ func (s *Service) monitorRoutine(stateChannel chan *feed.Event, stateSub event.S
|
||||
s.processBlock(s.ctx, data.SignedBlock)
|
||||
}
|
||||
}
|
||||
case event := <-opChannel:
|
||||
switch event.Type {
|
||||
case e := <-opChannel:
|
||||
switch e.Type {
|
||||
case operation.UnaggregatedAttReceived:
|
||||
data, ok := event.Data.(*operation.UnAggregatedAttReceivedData)
|
||||
data, ok := e.Data.(*operation.UnAggregatedAttReceivedData)
|
||||
if !ok {
|
||||
log.Error("Event feed data is not of type *operation.UnAggregatedAttReceivedData")
|
||||
} else {
|
||||
s.processUnaggregatedAttestation(s.ctx, data.Attestation)
|
||||
}
|
||||
case operation.AggregatedAttReceived:
|
||||
data, ok := event.Data.(*operation.AggregatedAttReceivedData)
|
||||
data, ok := e.Data.(*operation.AggregatedAttReceivedData)
|
||||
if !ok {
|
||||
log.Error("Event feed data is not of type *operation.AggregatedAttReceivedData")
|
||||
} else {
|
||||
s.processAggregatedAttestation(s.ctx, data.Attestation)
|
||||
}
|
||||
case operation.ExitReceived:
|
||||
data, ok := event.Data.(*operation.ExitReceivedData)
|
||||
data, ok := e.Data.(*operation.ExitReceivedData)
|
||||
if !ok {
|
||||
log.Error("Event feed data is not of type *operation.ExitReceivedData")
|
||||
} else {
|
||||
s.processExit(data.Exit)
|
||||
}
|
||||
case operation.SyncCommitteeContributionReceived:
|
||||
data, ok := event.Data.(*operation.SyncCommitteeContributionReceivedData)
|
||||
data, ok := e.Data.(*operation.SyncCommitteeContributionReceivedData)
|
||||
if !ok {
|
||||
log.Error("Event feed data is not of type *operation.SyncCommitteeContributionReceivedData")
|
||||
} else {
|
||||
|
||||
@@ -346,11 +346,11 @@ func TestService_BroadcastAttestationWithDiscoveryAttempts(t *testing.T) {
|
||||
|
||||
time.Sleep(500 * time.Millisecond) // libp2p fails without this delay...
|
||||
|
||||
peers := p.pubsub.ListPeers(topic)
|
||||
peers2 := p2.pubsub.ListPeers(topic)
|
||||
nodePeers := p.pubsub.ListPeers(topic)
|
||||
nodePeers2 := p2.pubsub.ListPeers(topic)
|
||||
|
||||
assert.Equal(t, 1, len(peers))
|
||||
assert.Equal(t, 1, len(peers2))
|
||||
assert.Equal(t, 1, len(nodePeers))
|
||||
assert.Equal(t, 1, len(nodePeers2))
|
||||
|
||||
// Async listen for the pubsub, must be before the broadcast.
|
||||
var wg sync.WaitGroup
|
||||
|
||||
@@ -215,8 +215,8 @@ func TestStaticPeering_PeersAreAdded(t *testing.T) {
|
||||
})
|
||||
}
|
||||
time.Sleep(4 * time.Second)
|
||||
peers := s.host.Network().Peers()
|
||||
assert.Equal(t, 5, len(peers), "Not all peers added to peerstore")
|
||||
ps := s.host.Network().Peers()
|
||||
assert.Equal(t, 5, len(ps), "Not all peers added to peerstore")
|
||||
require.NoError(t, s.Stop())
|
||||
exitRoutine <- true
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package p2p
|
||||
|
||||
import (
|
||||
pubsub_pb "github.com/libp2p/go-libp2p-pubsub/pb"
|
||||
pubsubpb "github.com/libp2p/go-libp2p-pubsub/pb"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/p2p/encoder"
|
||||
"github.com/prysmaticlabs/prysm/config/params"
|
||||
types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
|
||||
@@ -22,7 +22,7 @@ import (
|
||||
// Otherwise, set `message-id` to the first 20 bytes of the `SHA256` hash of
|
||||
// the concatenation of `MESSAGE_DOMAIN_INVALID_SNAPPY` with the raw message data,
|
||||
// i.e. `SHA256(MESSAGE_DOMAIN_INVALID_SNAPPY + message.data)[:20]`.
|
||||
func MsgID(genesisValidatorsRoot []byte, pmsg *pubsub_pb.Message) string {
|
||||
func MsgID(genesisValidatorsRoot []byte, pmsg *pubsubpb.Message) string {
|
||||
if pmsg == nil || pmsg.Data == nil || pmsg.Topic == nil {
|
||||
// Impossible condition that should
|
||||
// never be hit.
|
||||
@@ -71,7 +71,7 @@ func MsgID(genesisValidatorsRoot []byte, pmsg *pubsub_pb.Message) string {
|
||||
// + message.topic + snappy_decompress(message.data))[:20]. Otherwise, set message-id to the first 20 bytes of the SHA256 hash of the concatenation
|
||||
// of the following data: MESSAGE_DOMAIN_INVALID_SNAPPY, the length of the topic byte string (encoded as little-endian uint64),
|
||||
// the topic byte string, and the raw message data: i.e. SHA256(MESSAGE_DOMAIN_INVALID_SNAPPY + uint_to_bytes(uint64(len(message.topic))) + message.topic + message.data)[:20].
|
||||
func postAltairMsgID(pmsg *pubsub_pb.Message, fEpoch types.Epoch) string {
|
||||
func postAltairMsgID(pmsg *pubsubpb.Message, fEpoch types.Epoch) string {
|
||||
topic := *pmsg.Topic
|
||||
topicLen := len(topic)
|
||||
topicLenBytes := bytesutil.Uint64ToBytesLittleEndian(uint64(topicLen)) // topicLen cannot be negative
|
||||
|
||||
@@ -132,13 +132,13 @@ func TestProcessDeposit_InvalidPublicKey(t *testing.T) {
|
||||
leaf, err := deposits[0].Data.HashTreeRoot()
|
||||
require.NoError(t, err, "Could not hash deposit")
|
||||
|
||||
trie, err := trie.GenerateTrieFromItems([][]byte{leaf[:]}, params.BeaconConfig().DepositContractTreeDepth)
|
||||
generatedTrie, err := trie.GenerateTrieFromItems([][]byte{leaf[:]}, params.BeaconConfig().DepositContractTreeDepth)
|
||||
require.NoError(t, err)
|
||||
|
||||
deposits[0].Proof, err = trie.MerkleProof(0)
|
||||
deposits[0].Proof, err = generatedTrie.MerkleProof(0)
|
||||
require.NoError(t, err)
|
||||
|
||||
root, err := trie.HashTreeRoot()
|
||||
root, err := generatedTrie.HashTreeRoot()
|
||||
require.NoError(t, err)
|
||||
|
||||
eth1Data := ðpb.Eth1Data{
|
||||
@@ -176,10 +176,10 @@ func TestProcessDeposit_InvalidSignature(t *testing.T) {
|
||||
leaf, err := deposits[0].Data.HashTreeRoot()
|
||||
require.NoError(t, err, "Could not hash deposit")
|
||||
|
||||
trie, err := trie.GenerateTrieFromItems([][]byte{leaf[:]}, params.BeaconConfig().DepositContractTreeDepth)
|
||||
generatedTrie, err := trie.GenerateTrieFromItems([][]byte{leaf[:]}, params.BeaconConfig().DepositContractTreeDepth)
|
||||
require.NoError(t, err)
|
||||
|
||||
root, err := trie.HashTreeRoot()
|
||||
root, err := generatedTrie.HashTreeRoot()
|
||||
require.NoError(t, err)
|
||||
|
||||
eth1Data := ðpb.Eth1Data{
|
||||
@@ -213,15 +213,15 @@ func TestProcessDeposit_UnableToVerify(t *testing.T) {
|
||||
sig := keys[0].Sign([]byte{'F', 'A', 'K', 'E'})
|
||||
deposits[0].Data.Signature = sig.Marshal()
|
||||
|
||||
trie, _, err := util.DepositTrieFromDeposits(deposits)
|
||||
generatedTrie, _, err := util.DepositTrieFromDeposits(deposits)
|
||||
require.NoError(t, err)
|
||||
root, err := trie.HashTreeRoot()
|
||||
root, err := generatedTrie.HashTreeRoot()
|
||||
require.NoError(t, err)
|
||||
eth1Data := ðpb.Eth1Data{
|
||||
DepositCount: 1,
|
||||
DepositRoot: root[:],
|
||||
}
|
||||
proof, err := trie.MerkleProof(0)
|
||||
proof, err := generatedTrie.MerkleProof(0)
|
||||
require.NoError(t, err)
|
||||
deposits[0].Proof = proof
|
||||
err = web3Service.processDeposit(context.Background(), eth1Data, deposits[0])
|
||||
@@ -266,15 +266,15 @@ func TestProcessDeposit_IncompleteDeposit(t *testing.T) {
|
||||
sig := priv.Sign(signedRoot[:])
|
||||
deposit.Data.Signature = sig.Marshal()
|
||||
|
||||
trie, err := trie.NewTrie(params.BeaconConfig().DepositContractTreeDepth)
|
||||
generatedTrie, err := trie.NewTrie(params.BeaconConfig().DepositContractTreeDepth)
|
||||
require.NoError(t, err)
|
||||
root, err := trie.HashTreeRoot()
|
||||
root, err := generatedTrie.HashTreeRoot()
|
||||
require.NoError(t, err)
|
||||
eth1Data := ðpb.Eth1Data{
|
||||
DepositCount: 1,
|
||||
DepositRoot: root[:],
|
||||
}
|
||||
proof, err := trie.MerkleProof(0)
|
||||
proof, err := generatedTrie.MerkleProof(0)
|
||||
require.NoError(t, err)
|
||||
dataRoot, err := deposit.Data.HashTreeRoot()
|
||||
require.NoError(t, err)
|
||||
@@ -283,14 +283,14 @@ func TestProcessDeposit_IncompleteDeposit(t *testing.T) {
|
||||
factor := params.BeaconConfig().MaxEffectiveBalance / params.BeaconConfig().EffectiveBalanceIncrement
|
||||
// deposit till 31e9
|
||||
for i := 0; i < int(factor-1); i++ {
|
||||
assert.NoError(t, trie.Insert(dataRoot[:], i))
|
||||
assert.NoError(t, generatedTrie.Insert(dataRoot[:], i))
|
||||
|
||||
trieRoot, err := trie.HashTreeRoot()
|
||||
trieRoot, err := generatedTrie.HashTreeRoot()
|
||||
require.NoError(t, err)
|
||||
eth1Data.DepositRoot = trieRoot[:]
|
||||
eth1Data.DepositCount = uint64(i + 1)
|
||||
|
||||
deposit.Proof, err = trie.MerkleProof(i)
|
||||
deposit.Proof, err = generatedTrie.MerkleProof(i)
|
||||
require.NoError(t, err)
|
||||
err = web3Service.processDeposit(context.Background(), eth1Data, deposit)
|
||||
require.NoError(t, err, fmt.Sprintf("Could not process deposit at %d", i))
|
||||
|
||||
@@ -11,13 +11,13 @@ import (
|
||||
"github.com/ethereum/go-ethereum"
|
||||
"github.com/ethereum/go-ethereum/accounts/abi/bind"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
gethTypes "github.com/ethereum/go-ethereum/core/types"
|
||||
gethtypes "github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/feed"
|
||||
statefeed "github.com/prysmaticlabs/prysm/beacon-chain/core/feed/state"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
|
||||
coreState "github.com/prysmaticlabs/prysm/beacon-chain/core/transition"
|
||||
state_native "github.com/prysmaticlabs/prysm/beacon-chain/state/state-native"
|
||||
statenative "github.com/prysmaticlabs/prysm/beacon-chain/state/state-native"
|
||||
v1 "github.com/prysmaticlabs/prysm/beacon-chain/state/v1"
|
||||
"github.com/prysmaticlabs/prysm/config/features"
|
||||
"github.com/prysmaticlabs/prysm/config/params"
|
||||
@@ -89,7 +89,7 @@ func (s *Service) ProcessETH1Block(ctx context.Context, blkNum *big.Int) error {
|
||||
|
||||
// ProcessLog is the main method which handles the processing of all
|
||||
// logs from the deposit contract on the eth1 chain.
|
||||
func (s *Service) ProcessLog(ctx context.Context, depositLog gethTypes.Log) error {
|
||||
func (s *Service) ProcessLog(ctx context.Context, depositLog gethtypes.Log) error {
|
||||
s.processingLock.RLock()
|
||||
defer s.processingLock.RUnlock()
|
||||
// Process logs according to their event signature.
|
||||
@@ -109,7 +109,7 @@ func (s *Service) ProcessLog(ctx context.Context, depositLog gethTypes.Log) erro
|
||||
// ProcessDepositLog processes the log which had been received from
|
||||
// the eth1 chain by trying to ascertain which participant deposited
|
||||
// in the contract.
|
||||
func (s *Service) ProcessDepositLog(ctx context.Context, depositLog gethTypes.Log) error {
|
||||
func (s *Service) ProcessDepositLog(ctx context.Context, depositLog gethtypes.Log) error {
|
||||
pubkey, withdrawalCredentials, amount, signature, merkleTreeIndex, err := contracts.UnpackDepositLogData(depositLog.Data)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "Could not unpack log")
|
||||
@@ -286,7 +286,7 @@ func (s *Service) processPastLogs(ctx context.Context) error {
|
||||
currentBlockNum = deploymentBlock
|
||||
}
|
||||
// To store all blocks.
|
||||
headersMap := make(map[uint64]*gethTypes.Header)
|
||||
headersMap := make(map[uint64]*gethtypes.Header)
|
||||
rawLogCount, err := s.depositContractCaller.GetDepositCount(&bind.CallOpts{})
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -343,7 +343,7 @@ func (s *Service) processPastLogs(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Service) processBlockInBatch(ctx context.Context, currentBlockNum uint64, latestFollowHeight uint64, batchSize uint64, additiveFactor uint64, logCount uint64, headersMap map[uint64]*gethTypes.Header) (uint64, uint64, error) {
|
||||
func (s *Service) processBlockInBatch(ctx context.Context, currentBlockNum uint64, latestFollowHeight uint64, batchSize uint64, additiveFactor uint64, logCount uint64, headersMap map[uint64]*gethtypes.Header) (uint64, uint64, error) {
|
||||
// Batch request the desired headers and store them in a
|
||||
// map for quick access.
|
||||
requestHeaders := func(startBlk uint64, endBlk uint64) error {
|
||||
@@ -490,11 +490,11 @@ func (s *Service) processChainStartFromBlockNum(ctx context.Context, blkNum *big
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Service) processChainStartFromHeader(ctx context.Context, header *gethTypes.Header) {
|
||||
func (s *Service) processChainStartFromHeader(ctx context.Context, header *gethtypes.Header) {
|
||||
s.processChainStartIfReady(ctx, header.Hash(), header.Number, header.Time)
|
||||
}
|
||||
|
||||
func (s *Service) checkHeaderRange(ctx context.Context, start, end uint64, headersMap map[uint64]*gethTypes.Header,
|
||||
func (s *Service) checkHeaderRange(ctx context.Context, start, end uint64, headersMap map[uint64]*gethtypes.Header,
|
||||
requestHeaders func(uint64, uint64) error) error {
|
||||
for i := start; i <= end; i++ {
|
||||
if !s.chainStartData.Chainstarted {
|
||||
@@ -544,7 +544,7 @@ func (s *Service) savePowchainData(ctx context.Context) error {
|
||||
var pbState *ethpb.BeaconState
|
||||
var err error
|
||||
if features.Get().EnableNativeState {
|
||||
pbState, err = state_native.ProtobufBeaconStatePhase0(s.preGenesisState.InnerStateUnsafe())
|
||||
pbState, err = statenative.ProtobufBeaconStatePhase0(s.preGenesisState.InnerStateUnsafe())
|
||||
} else {
|
||||
pbState, err = v1.ProtobufBeaconState(s.preGenesisState.InnerStateUnsafe())
|
||||
}
|
||||
|
||||
@@ -915,6 +915,6 @@ func (s *slowRPCClient) BatchCall(b []rpc.BatchElem) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *slowRPCClient) CallContext(ctx context.Context, result interface{}, method string, args ...interface{}) error {
|
||||
func (s *slowRPCClient) CallContext(_ context.Context, _ interface{}, _ string, _ ...interface{}) error {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ func handleGetBeaconBlockSSZV2(m *apimiddleware.ApiProxyMiddleware, endpoint api
|
||||
}
|
||||
|
||||
func handleSubmitBlockSSZ(m *apimiddleware.ApiProxyMiddleware, endpoint apimiddleware.Endpoint, w http.ResponseWriter, req *http.Request) (handled bool) {
|
||||
return handlePostSSZ(m, endpoint, w, req, sszConfig{})
|
||||
return handlePostSSZ(m, endpoint, w, req)
|
||||
}
|
||||
|
||||
func handleSubmitBlindedBlockSSZ(
|
||||
@@ -74,7 +74,7 @@ func handleSubmitBlindedBlockSSZ(
|
||||
w http.ResponseWriter,
|
||||
req *http.Request,
|
||||
) (handled bool) {
|
||||
return handlePostSSZ(m, endpoint, w, req, sszConfig{})
|
||||
return handlePostSSZ(m, endpoint, w, req)
|
||||
}
|
||||
|
||||
func handleProduceBlockSSZ(m *apimiddleware.ApiProxyMiddleware, endpoint apimiddleware.Endpoint, w http.ResponseWriter, req *http.Request) (handled bool) {
|
||||
@@ -157,13 +157,7 @@ func handleGetSSZ(
|
||||
return true
|
||||
}
|
||||
|
||||
func handlePostSSZ(
|
||||
m *apimiddleware.ApiProxyMiddleware,
|
||||
endpoint apimiddleware.Endpoint,
|
||||
w http.ResponseWriter,
|
||||
req *http.Request,
|
||||
config sszConfig,
|
||||
) (handled bool) {
|
||||
func handlePostSSZ(m *apimiddleware.ApiProxyMiddleware, endpoint apimiddleware.Endpoint, w http.ResponseWriter, req *http.Request) (handled bool) {
|
||||
if !sszPosted(req) {
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -158,14 +158,14 @@ func (vs *Server) GetProposerDuties(ctx context.Context, req *ethpbv1.ProposerDu
|
||||
}
|
||||
|
||||
duties := make([]*ethpbv1.ProposerDuty, 0)
|
||||
for index, slots := range proposals {
|
||||
for index, ss := range proposals {
|
||||
val, err := s.ValidatorAtIndexReadOnly(index)
|
||||
if err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "Could not get validator: %v", err)
|
||||
}
|
||||
pubkey48 := val.PublicKey()
|
||||
pubkey := pubkey48[:]
|
||||
for _, s := range slots {
|
||||
for _, s := range ss {
|
||||
duties = append(duties, ðpbv1.ProposerDuty{
|
||||
Pubkey: pubkey,
|
||||
ValidatorIndex: index,
|
||||
|
||||
@@ -26,7 +26,7 @@ import (
|
||||
mockPOW "github.com/prysmaticlabs/prysm/beacon-chain/powchain/testing"
|
||||
v1alpha1validator "github.com/prysmaticlabs/prysm/beacon-chain/rpc/prysm/v1alpha1/validator"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/rpc/testutil"
|
||||
beaconState "github.com/prysmaticlabs/prysm/beacon-chain/state"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/state"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/state/stategen"
|
||||
mockSync "github.com/prysmaticlabs/prysm/beacon-chain/sync/initial-sync/testing"
|
||||
fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams"
|
||||
@@ -569,7 +569,7 @@ func TestGetSyncCommitteeDuties(t *testing.T) {
|
||||
}
|
||||
require.NoError(t, newSyncPeriodSt.SetNextSyncCommittee(nextCommittee))
|
||||
|
||||
stateFetchFn := func(slot types.Slot) beaconState.BeaconState {
|
||||
stateFetchFn := func(slot types.Slot) state.BeaconState {
|
||||
if slot < newSyncPeriodStartSlot {
|
||||
return st
|
||||
} else {
|
||||
|
||||
@@ -222,7 +222,7 @@ func (ns *Server) ListPeers(ctx context.Context, _ *empty.Empty) (*ethpb.Peers,
|
||||
}
|
||||
|
||||
// GetETH1ConnectionStatus gets data about the ETH1 endpoints.
|
||||
func (ns *Server) GetETH1ConnectionStatus(ctx context.Context, _ *empty.Empty) (*ethpb.ETH1ConnectionStatus, error) {
|
||||
func (ns *Server) GetETH1ConnectionStatus(_ context.Context, _ *empty.Empty) (*ethpb.ETH1ConnectionStatus, error) {
|
||||
var errStrs []string
|
||||
errs := ns.POWChainInfoFetcher.ETH1ConnectionErrors()
|
||||
// Extract string version of the errors.
|
||||
|
||||
@@ -238,7 +238,7 @@ func TestGetBellatrixDuties_SyncCommitteeOK(t *testing.T) {
|
||||
require.NoError(t, bs.SetSlot(params.BeaconConfig().SlotsPerEpoch*types.Slot(params.BeaconConfig().EpochsPerSyncCommitteePeriod)-1))
|
||||
require.NoError(t, helpers.UpdateSyncCommitteeCache(bs))
|
||||
|
||||
bs, err = execution.UpgradeToBellatrix(context.Background(), bs)
|
||||
bs, err = execution.UpgradeToBellatrix(bs)
|
||||
require.NoError(t, err)
|
||||
|
||||
pubkeysAs48ByteType := make([][fieldparams.BLSPubkeyLength]byte, len(pubKeys))
|
||||
|
||||
@@ -555,21 +555,21 @@ func TestServer_SubscribeCommitteeSubnets_DifferentLengthSlots(t *testing.T) {
|
||||
OperationNotifier: (&mock.ChainService{}).OperationNotifier(),
|
||||
}
|
||||
|
||||
var slots []types.Slot
|
||||
var ss []types.Slot
|
||||
var comIdxs []types.CommitteeIndex
|
||||
var isAggregator []bool
|
||||
|
||||
for i := types.Slot(100); i < 200; i++ {
|
||||
slots = append(slots, i)
|
||||
ss = append(ss, i)
|
||||
comIdxs = append(comIdxs, types.CommitteeIndex(randGen.Int63n(64)))
|
||||
boolVal := randGen.Uint64()%2 == 0
|
||||
isAggregator = append(isAggregator, boolVal)
|
||||
}
|
||||
|
||||
slots = append(slots, 321)
|
||||
ss = append(ss, 321)
|
||||
|
||||
_, err := attesterServer.SubscribeCommitteeSubnets(context.Background(), ðpb.CommitteeSubnetsSubscribeRequest{
|
||||
Slots: slots,
|
||||
Slots: ss,
|
||||
CommitteeIds: comIdxs,
|
||||
IsAggregator: isAggregator,
|
||||
})
|
||||
@@ -601,19 +601,19 @@ func TestServer_SubscribeCommitteeSubnets_MultipleSlots(t *testing.T) {
|
||||
OperationNotifier: (&mock.ChainService{}).OperationNotifier(),
|
||||
}
|
||||
|
||||
var slots []types.Slot
|
||||
var ss []types.Slot
|
||||
var comIdxs []types.CommitteeIndex
|
||||
var isAggregator []bool
|
||||
|
||||
for i := types.Slot(100); i < 200; i++ {
|
||||
slots = append(slots, i)
|
||||
ss = append(ss, i)
|
||||
comIdxs = append(comIdxs, types.CommitteeIndex(randGen.Int63n(64)))
|
||||
boolVal := randGen.Uint64()%2 == 0
|
||||
isAggregator = append(isAggregator, boolVal)
|
||||
}
|
||||
|
||||
_, err = attesterServer.SubscribeCommitteeSubnets(context.Background(), ðpb.CommitteeSubnetsSubscribeRequest{
|
||||
Slots: slots,
|
||||
Slots: ss,
|
||||
CommitteeIds: comIdxs,
|
||||
IsAggregator: isAggregator,
|
||||
})
|
||||
|
||||
@@ -63,13 +63,13 @@ func (vs *Server) eth1DataMajorityVote(ctx context.Context, beaconState state.Be
|
||||
}
|
||||
|
||||
if lastBlockDepositCount >= vs.HeadFetcher.HeadETH1Data().DepositCount {
|
||||
hash, err := vs.Eth1BlockFetcher.BlockHashByHeight(ctx, lastBlockByLatestValidTime.Number)
|
||||
h, err := vs.Eth1BlockFetcher.BlockHashByHeight(ctx, lastBlockByLatestValidTime.Number)
|
||||
if err != nil {
|
||||
log.WithError(err).Error("Could not get hash of last block by latest valid time")
|
||||
return vs.randomETH1DataVote(ctx)
|
||||
}
|
||||
return ðpb.Eth1Data{
|
||||
BlockHash: hash.Bytes(),
|
||||
BlockHash: h.Bytes(),
|
||||
DepositCount: lastBlockDepositCount,
|
||||
DepositRoot: lastBlockDepositRoot[:],
|
||||
}, nil
|
||||
|
||||
@@ -1040,10 +1040,10 @@ func TestProposer_DepositTrie_UtilizesCachedFinalizedDeposits(t *testing.T) {
|
||||
HeadFetcher: &mock.ChainService{State: beaconState, Root: blkRoot[:]},
|
||||
}
|
||||
|
||||
trie, err := bs.depositTrie(ctx, ðpb.Eth1Data{}, big.NewInt(int64(params.BeaconConfig().Eth1FollowDistance)))
|
||||
dt, err := bs.depositTrie(ctx, ðpb.Eth1Data{}, big.NewInt(int64(params.BeaconConfig().Eth1FollowDistance)))
|
||||
require.NoError(t, err)
|
||||
|
||||
actualRoot, err := trie.HashTreeRoot()
|
||||
actualRoot, err := dt.HashTreeRoot()
|
||||
require.NoError(t, err)
|
||||
expectedRoot, err := depositTrie.HashTreeRoot()
|
||||
require.NoError(t, err)
|
||||
@@ -1168,12 +1168,12 @@ func TestProposer_DepositTrie_RebuildTrie(t *testing.T) {
|
||||
HeadFetcher: &mock.ChainService{State: beaconState, Root: blkRoot[:]},
|
||||
}
|
||||
|
||||
trie, err := bs.depositTrie(ctx, ðpb.Eth1Data{}, big.NewInt(int64(params.BeaconConfig().Eth1FollowDistance)))
|
||||
dt, err := bs.depositTrie(ctx, ðpb.Eth1Data{}, big.NewInt(int64(params.BeaconConfig().Eth1FollowDistance)))
|
||||
require.NoError(t, err)
|
||||
|
||||
expectedRoot, err := depositTrie.HashTreeRoot()
|
||||
require.NoError(t, err)
|
||||
actualRoot, err := trie.HashTreeRoot()
|
||||
actualRoot, err := dt.HashTreeRoot()
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, expectedRoot, actualRoot, "Incorrect deposit trie root")
|
||||
|
||||
@@ -1192,51 +1192,51 @@ func TestProposer_ValidateDepositTrie(t *testing.T) {
|
||||
return ðpb.Eth1Data{DepositRoot: []byte{}, DepositCount: 10, BlockHash: []byte{}}
|
||||
},
|
||||
trieCreator: func() *trie.SparseMerkleTrie {
|
||||
trie, err := trie.NewTrie(params.BeaconConfig().DepositContractTreeDepth)
|
||||
newTrie, err := trie.NewTrie(params.BeaconConfig().DepositContractTreeDepth)
|
||||
assert.NoError(t, err)
|
||||
return trie
|
||||
return newTrie
|
||||
},
|
||||
success: false,
|
||||
},
|
||||
{
|
||||
name: "invalid deposit root",
|
||||
eth1dataCreator: func() *ethpb.Eth1Data {
|
||||
trie, err := trie.NewTrie(params.BeaconConfig().DepositContractTreeDepth)
|
||||
newTrie, err := trie.NewTrie(params.BeaconConfig().DepositContractTreeDepth)
|
||||
assert.NoError(t, err)
|
||||
assert.NoError(t, trie.Insert([]byte{'a'}, 0))
|
||||
assert.NoError(t, trie.Insert([]byte{'b'}, 1))
|
||||
assert.NoError(t, trie.Insert([]byte{'c'}, 2))
|
||||
assert.NoError(t, newTrie.Insert([]byte{'a'}, 0))
|
||||
assert.NoError(t, newTrie.Insert([]byte{'b'}, 1))
|
||||
assert.NoError(t, newTrie.Insert([]byte{'c'}, 2))
|
||||
return ðpb.Eth1Data{DepositRoot: []byte{'B'}, DepositCount: 3, BlockHash: []byte{}}
|
||||
},
|
||||
trieCreator: func() *trie.SparseMerkleTrie {
|
||||
trie, err := trie.NewTrie(params.BeaconConfig().DepositContractTreeDepth)
|
||||
newTrie, err := trie.NewTrie(params.BeaconConfig().DepositContractTreeDepth)
|
||||
assert.NoError(t, err)
|
||||
assert.NoError(t, trie.Insert([]byte{'a'}, 0))
|
||||
assert.NoError(t, trie.Insert([]byte{'b'}, 1))
|
||||
assert.NoError(t, trie.Insert([]byte{'c'}, 2))
|
||||
return trie
|
||||
assert.NoError(t, newTrie.Insert([]byte{'a'}, 0))
|
||||
assert.NoError(t, newTrie.Insert([]byte{'b'}, 1))
|
||||
assert.NoError(t, newTrie.Insert([]byte{'c'}, 2))
|
||||
return newTrie
|
||||
},
|
||||
success: false,
|
||||
},
|
||||
{
|
||||
name: "valid deposit trie",
|
||||
eth1dataCreator: func() *ethpb.Eth1Data {
|
||||
trie, err := trie.NewTrie(params.BeaconConfig().DepositContractTreeDepth)
|
||||
newTrie, err := trie.NewTrie(params.BeaconConfig().DepositContractTreeDepth)
|
||||
assert.NoError(t, err)
|
||||
assert.NoError(t, trie.Insert([]byte{'a'}, 0))
|
||||
assert.NoError(t, trie.Insert([]byte{'b'}, 1))
|
||||
assert.NoError(t, trie.Insert([]byte{'c'}, 2))
|
||||
rt, err := trie.HashTreeRoot()
|
||||
assert.NoError(t, newTrie.Insert([]byte{'a'}, 0))
|
||||
assert.NoError(t, newTrie.Insert([]byte{'b'}, 1))
|
||||
assert.NoError(t, newTrie.Insert([]byte{'c'}, 2))
|
||||
rt, err := newTrie.HashTreeRoot()
|
||||
require.NoError(t, err)
|
||||
return ðpb.Eth1Data{DepositRoot: rt[:], DepositCount: 3, BlockHash: []byte{}}
|
||||
},
|
||||
trieCreator: func() *trie.SparseMerkleTrie {
|
||||
trie, err := trie.NewTrie(params.BeaconConfig().DepositContractTreeDepth)
|
||||
newTrie, err := trie.NewTrie(params.BeaconConfig().DepositContractTreeDepth)
|
||||
assert.NoError(t, err)
|
||||
assert.NoError(t, trie.Insert([]byte{'a'}, 0))
|
||||
assert.NoError(t, trie.Insert([]byte{'b'}, 1))
|
||||
assert.NoError(t, trie.Insert([]byte{'c'}, 2))
|
||||
return trie
|
||||
assert.NoError(t, newTrie.Insert([]byte{'a'}, 0))
|
||||
assert.NoError(t, newTrie.Insert([]byte{'b'}, 1))
|
||||
assert.NoError(t, newTrie.Insert([]byte{'c'}, 2))
|
||||
return newTrie
|
||||
},
|
||||
success: true,
|
||||
},
|
||||
@@ -1806,9 +1806,9 @@ func TestProposer_FilterAttestation(t *testing.T) {
|
||||
genesis := util.NewBeaconBlock()
|
||||
|
||||
numValidators := uint64(64)
|
||||
state, privKeys := util.DeterministicGenesisState(t, numValidators)
|
||||
require.NoError(t, state.SetGenesisValidatorsRoot(params.BeaconConfig().ZeroHash[:]))
|
||||
assert.NoError(t, state.SetSlot(1))
|
||||
st, privKeys := util.DeterministicGenesisState(t, numValidators)
|
||||
require.NoError(t, st.SetGenesisValidatorsRoot(params.BeaconConfig().ZeroHash[:]))
|
||||
assert.NoError(t, st.SetSlot(1))
|
||||
|
||||
genesisRoot, err := genesis.Block.HashTreeRoot()
|
||||
require.NoError(t, err)
|
||||
@@ -1857,12 +1857,12 @@ func TestProposer_FilterAttestation(t *testing.T) {
|
||||
},
|
||||
AggregationBits: bitfield.Bitlist{0b00000110},
|
||||
})
|
||||
committee, err := helpers.BeaconCommitteeFromState(context.Background(), state, atts[i].Data.Slot, atts[i].Data.CommitteeIndex)
|
||||
committee, err := helpers.BeaconCommitteeFromState(context.Background(), st, atts[i].Data.Slot, atts[i].Data.CommitteeIndex)
|
||||
assert.NoError(t, err)
|
||||
attestingIndices, err := attestation.AttestingIndices(atts[i].AggregationBits, committee)
|
||||
require.NoError(t, err)
|
||||
assert.NoError(t, err)
|
||||
domain, err := signing.Domain(state.Fork(), 0, params.BeaconConfig().DomainBeaconAttester, params.BeaconConfig().ZeroHash[:])
|
||||
domain, err := signing.Domain(st.Fork(), 0, params.BeaconConfig().DomainBeaconAttester, params.BeaconConfig().ZeroHash[:])
|
||||
require.NoError(t, err)
|
||||
sigs := make([]bls.Signature, len(attestingIndices))
|
||||
zeroSig := [96]byte{}
|
||||
@@ -1888,10 +1888,10 @@ func TestProposer_FilterAttestation(t *testing.T) {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
proposerServer := &Server{
|
||||
AttPool: attestations.NewPool(),
|
||||
HeadFetcher: &mock.ChainService{State: state, Root: genesisRoot[:]},
|
||||
HeadFetcher: &mock.ChainService{State: st, Root: genesisRoot[:]},
|
||||
}
|
||||
atts := tt.inputAtts()
|
||||
received, err := proposerServer.validateAndDeleteAttsInPool(context.Background(), state, atts)
|
||||
received, err := proposerServer.validateAndDeleteAttsInPool(context.Background(), st, atts)
|
||||
if tt.wantedErr != "" {
|
||||
assert.ErrorContains(t, tt.wantedErr, err)
|
||||
assert.Equal(t, nil, received)
|
||||
@@ -2505,8 +2505,8 @@ func TestProposer_PrepareBeaconProposer(t *testing.T) {
|
||||
}
|
||||
|
||||
func majorityVoteBoundaryTime(slot types.Slot) (uint64, uint64) {
|
||||
slots := params.BeaconConfig().SlotsPerEpoch.Mul(uint64(params.BeaconConfig().EpochsPerEth1VotingPeriod))
|
||||
slotStartTime := uint64(mockPOW.GenesisTime) + uint64((slot - (slot % (slots))).Mul(params.BeaconConfig().SecondsPerSlot))
|
||||
s := params.BeaconConfig().SlotsPerEpoch.Mul(uint64(params.BeaconConfig().EpochsPerEth1VotingPeriod))
|
||||
slotStartTime := uint64(mockPOW.GenesisTime) + uint64((slot - (slot % (s))).Mul(params.BeaconConfig().SecondsPerSlot))
|
||||
earliestValidTime := slotStartTime - 2*params.BeaconConfig().SecondsPerETH1Block*params.BeaconConfig().Eth1FollowDistance
|
||||
latestValidTime := slotStartTime - params.BeaconConfig().SecondsPerETH1Block*params.BeaconConfig().Eth1FollowDistance
|
||||
|
||||
|
||||
@@ -140,7 +140,7 @@ func TestWaitForActivation_ValidatorOriginallyExists(t *testing.T) {
|
||||
root, err := depositTrie.HashTreeRoot()
|
||||
require.NoError(t, err)
|
||||
assert.NoError(t, depositCache.InsertDeposit(ctx, deposit, 10 /*blockNum*/, 0, root))
|
||||
trie, err := v1.InitializeFromProtoUnsafe(beaconState)
|
||||
s, err := v1.InitializeFromProtoUnsafe(beaconState)
|
||||
require.NoError(t, err)
|
||||
vs := &Server{
|
||||
Ctx: context.Background(),
|
||||
@@ -148,7 +148,7 @@ func TestWaitForActivation_ValidatorOriginallyExists(t *testing.T) {
|
||||
BlockFetcher: &mockPOW.POWChain{},
|
||||
Eth1InfoFetcher: &mockPOW.POWChain{},
|
||||
DepositFetcher: depositCache,
|
||||
HeadFetcher: &mockChain.ChainService{State: trie, Root: genesisRoot[:]},
|
||||
HeadFetcher: &mockChain.ChainService{State: s, Root: genesisRoot[:]},
|
||||
}
|
||||
req := ðpb.ValidatorActivationRequest{
|
||||
PublicKeys: [][]byte{pubKey1, pubKey2},
|
||||
@@ -219,12 +219,12 @@ func TestWaitForActivation_MultipleStatuses(t *testing.T) {
|
||||
block := util.NewBeaconBlock()
|
||||
genesisRoot, err := block.Block.HashTreeRoot()
|
||||
require.NoError(t, err, "Could not get signing root")
|
||||
trie, err := v1.InitializeFromProtoUnsafe(beaconState)
|
||||
s, err := v1.InitializeFromProtoUnsafe(beaconState)
|
||||
require.NoError(t, err)
|
||||
vs := &Server{
|
||||
Ctx: context.Background(),
|
||||
ChainStartFetcher: &mockPOW.POWChain{},
|
||||
HeadFetcher: &mockChain.ChainService{State: trie, Root: genesisRoot[:]},
|
||||
HeadFetcher: &mockChain.ChainService{State: s, Root: genesisRoot[:]},
|
||||
}
|
||||
req := ðpb.ValidatorActivationRequest{
|
||||
PublicKeys: [][]byte{pubKey1, pubKey2, pubKey3},
|
||||
|
||||
@@ -334,9 +334,9 @@ func (vs *Server) validatorStatus(
|
||||
log.Warn("Not connected to ETH1. Cannot determine validator ETH1 deposit.")
|
||||
} else {
|
||||
// Check if there was a deposit deposit.
|
||||
deposit, eth1BlockNumBigInt := vs.DepositFetcher.DepositByPubkey(ctx, pubKey)
|
||||
d, eth1BlockNumBigInt := vs.DepositFetcher.DepositByPubkey(ctx, pubKey)
|
||||
if eth1BlockNumBigInt != nil {
|
||||
resp.Status = depositStatus(deposit.Data.Amount)
|
||||
resp.Status = depositStatus(d.Data.Amount)
|
||||
resp.Eth1DepositBlockNumber = eth1BlockNumBigInt.Uint64()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -180,10 +180,10 @@ func TestValidatorStatus_Pending(t *testing.T) {
|
||||
genesisRoot, err := block.Block.HashTreeRoot()
|
||||
require.NoError(t, err, "Could not get signing root")
|
||||
// Pending active because activation epoch is still defaulted at far future slot.
|
||||
state, err := util.NewBeaconState()
|
||||
st, err := util.NewBeaconState()
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, state.SetSlot(5000))
|
||||
err = state.SetValidators([]*ethpb.Validator{
|
||||
require.NoError(t, st.SetSlot(5000))
|
||||
err = st.SetValidators([]*ethpb.Validator{
|
||||
{
|
||||
ActivationEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
@@ -223,7 +223,7 @@ func TestValidatorStatus_Pending(t *testing.T) {
|
||||
BlockFetcher: p,
|
||||
Eth1InfoFetcher: p,
|
||||
DepositFetcher: depositCache,
|
||||
HeadFetcher: &mockChain.ChainService{State: state, Root: genesisRoot[:]},
|
||||
HeadFetcher: &mockChain.ChainService{State: st, Root: genesisRoot[:]},
|
||||
}
|
||||
req := ðpb.ValidatorStatusRequest{
|
||||
PublicKey: pubKey,
|
||||
@@ -266,7 +266,7 @@ func TestValidatorStatus_Active(t *testing.T) {
|
||||
genesisRoot, err := block.Block.HashTreeRoot()
|
||||
require.NoError(t, err, "Could not get signing root")
|
||||
|
||||
state := ðpb.BeaconState{
|
||||
st := ðpb.BeaconState{
|
||||
GenesisTime: uint64(time.Unix(0, 0).Unix()),
|
||||
Slot: 10000,
|
||||
Validators: []*ethpb.Validator{{
|
||||
@@ -275,7 +275,7 @@ func TestValidatorStatus_Active(t *testing.T) {
|
||||
WithdrawableEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
PublicKey: pubKey},
|
||||
}}
|
||||
stateObj, err := v1.InitializeFromProtoUnsafe(state)
|
||||
stateObj, err := v1.InitializeFromProtoUnsafe(st)
|
||||
require.NoError(t, err)
|
||||
|
||||
timestamp := time.Unix(int64(params.BeaconConfig().Eth1FollowDistance), 0).Unix()
|
||||
@@ -320,7 +320,7 @@ func TestValidatorStatus_Exiting(t *testing.T) {
|
||||
genesisRoot, err := block.Block.HashTreeRoot()
|
||||
require.NoError(t, err, "Could not get signing root")
|
||||
|
||||
state := ðpb.BeaconState{
|
||||
st := ðpb.BeaconState{
|
||||
Slot: slot,
|
||||
Validators: []*ethpb.Validator{{
|
||||
PublicKey: pubKey,
|
||||
@@ -328,7 +328,7 @@ func TestValidatorStatus_Exiting(t *testing.T) {
|
||||
ExitEpoch: exitEpoch,
|
||||
WithdrawableEpoch: withdrawableEpoch},
|
||||
}}
|
||||
stateObj, err := v1.InitializeFromProtoUnsafe(state)
|
||||
stateObj, err := v1.InitializeFromProtoUnsafe(st)
|
||||
require.NoError(t, err)
|
||||
depData := ðpb.Deposit_Data{
|
||||
PublicKey: pubKey,
|
||||
@@ -380,14 +380,14 @@ func TestValidatorStatus_Slashing(t *testing.T) {
|
||||
genesisRoot, err := block.Block.HashTreeRoot()
|
||||
require.NoError(t, err, "Could not get signing root")
|
||||
|
||||
state := ðpb.BeaconState{
|
||||
st := ðpb.BeaconState{
|
||||
Slot: slot,
|
||||
Validators: []*ethpb.Validator{{
|
||||
Slashed: true,
|
||||
PublicKey: pubKey,
|
||||
WithdrawableEpoch: epoch + 1},
|
||||
}}
|
||||
stateObj, err := v1.InitializeFromProtoUnsafe(state)
|
||||
stateObj, err := v1.InitializeFromProtoUnsafe(st)
|
||||
require.NoError(t, err)
|
||||
depData := ðpb.Deposit_Data{
|
||||
PublicKey: pubKey,
|
||||
@@ -440,10 +440,10 @@ func TestValidatorStatus_Exited(t *testing.T) {
|
||||
require.NoError(t, err, "Could not get signing root")
|
||||
params.SetupTestConfigCleanup(t)
|
||||
params.OverrideBeaconConfig(params.MainnetConfig().Copy())
|
||||
state, err := util.NewBeaconState()
|
||||
st, err := util.NewBeaconState()
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, state.SetSlot(slot))
|
||||
err = state.SetValidators([]*ethpb.Validator{{
|
||||
require.NoError(t, st.SetSlot(slot))
|
||||
err = st.SetValidators([]*ethpb.Validator{{
|
||||
PublicKey: pubKey,
|
||||
WithdrawableEpoch: epoch + 1,
|
||||
WithdrawalCredentials: make([]byte, 32)},
|
||||
@@ -477,7 +477,7 @@ func TestValidatorStatus_Exited(t *testing.T) {
|
||||
Eth1InfoFetcher: p,
|
||||
BlockFetcher: p,
|
||||
DepositFetcher: depositCache,
|
||||
HeadFetcher: &mockChain.ChainService{State: state, Root: genesisRoot[:]},
|
||||
HeadFetcher: &mockChain.ChainService{State: st, Root: genesisRoot[:]},
|
||||
}
|
||||
req := ðpb.ValidatorStatusRequest{
|
||||
PublicKey: pubKey,
|
||||
@@ -677,10 +677,10 @@ func TestValidatorStatus_CorrectActivationQueue(t *testing.T) {
|
||||
WithdrawableEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
},
|
||||
}
|
||||
state, err := util.NewBeaconState()
|
||||
st, err := util.NewBeaconState()
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, state.SetValidators(validators))
|
||||
require.NoError(t, state.SetSlot(currentSlot))
|
||||
require.NoError(t, st.SetValidators(validators))
|
||||
require.NoError(t, st.SetSlot(currentSlot))
|
||||
|
||||
depositTrie, err := trie.NewTrie(params.BeaconConfig().DepositContractTreeDepth)
|
||||
require.NoError(t, err, "Could not setup deposit trie")
|
||||
@@ -714,7 +714,7 @@ func TestValidatorStatus_CorrectActivationQueue(t *testing.T) {
|
||||
BlockFetcher: p,
|
||||
Eth1InfoFetcher: p,
|
||||
DepositFetcher: depositCache,
|
||||
HeadFetcher: &mockChain.ChainService{State: state, Root: genesisRoot[:]},
|
||||
HeadFetcher: &mockChain.ChainService{State: st, Root: genesisRoot[:]},
|
||||
}
|
||||
req := ðpb.ValidatorStatusRequest{
|
||||
PublicKey: pbKey,
|
||||
|
||||
@@ -11,8 +11,8 @@ import (
|
||||
|
||||
middleware "github.com/grpc-ecosystem/go-grpc-middleware"
|
||||
recovery "github.com/grpc-ecosystem/go-grpc-middleware/recovery"
|
||||
grpc_opentracing "github.com/grpc-ecosystem/go-grpc-middleware/tracing/opentracing"
|
||||
grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
|
||||
grpcopentracing "github.com/grpc-ecosystem/go-grpc-middleware/tracing/opentracing"
|
||||
grpcprometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/blockchain"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/cache"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/cache/depositcache"
|
||||
@@ -140,16 +140,16 @@ func NewService(ctx context.Context, cfg *Config) *Service {
|
||||
recovery.StreamServerInterceptor(
|
||||
recovery.WithRecoveryHandlerContext(tracing.RecoveryHandlerFunc),
|
||||
),
|
||||
grpc_prometheus.StreamServerInterceptor,
|
||||
grpc_opentracing.StreamServerInterceptor(),
|
||||
grpcprometheus.StreamServerInterceptor,
|
||||
grpcopentracing.StreamServerInterceptor(),
|
||||
s.validatorStreamConnectionInterceptor,
|
||||
)),
|
||||
grpc.UnaryInterceptor(middleware.ChainUnaryServer(
|
||||
recovery.UnaryServerInterceptor(
|
||||
recovery.WithRecoveryHandlerContext(tracing.RecoveryHandlerFunc),
|
||||
),
|
||||
grpc_prometheus.UnaryServerInterceptor,
|
||||
grpc_opentracing.UnaryServerInterceptor(),
|
||||
grpcprometheus.UnaryServerInterceptor,
|
||||
grpcopentracing.UnaryServerInterceptor(),
|
||||
s.validatorUnaryConnectionInterceptor,
|
||||
)),
|
||||
grpc.MaxRecvMsgSize(s.cfg.MaxMsgSize),
|
||||
@@ -176,7 +176,7 @@ var _ stategen.CurrentSlotter = blockchain.ChainInfoFetcher(nil)
|
||||
|
||||
// Start the gRPC server.
|
||||
func (s *Service) Start() {
|
||||
grpc_prometheus.EnableHandlingTimeHistogram()
|
||||
grpcprometheus.EnableHandlingTimeHistogram()
|
||||
|
||||
var stateCache stategen.CachedGetter
|
||||
if s.cfg.StateGen != nil {
|
||||
|
||||
@@ -476,9 +476,9 @@ func Test_epochUpdateForValidators(t *testing.T) {
|
||||
func Test_applyAttestationForValidator_MinSpanChunk(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
slasherDB := dbtest.SetupSlasherDB(t)
|
||||
params := DefaultParams()
|
||||
defaultParams := DefaultParams()
|
||||
srv := &Service{
|
||||
params: params,
|
||||
params: defaultParams,
|
||||
serviceCfg: &ServiceConfig{
|
||||
Database: slasherDB,
|
||||
StateNotifier: &mock.MockStateNotifier{},
|
||||
@@ -486,7 +486,7 @@ func Test_applyAttestationForValidator_MinSpanChunk(t *testing.T) {
|
||||
latestEpochWrittenForValidator: map[types.ValidatorIndex]types.Epoch{},
|
||||
}
|
||||
// We initialize an empty chunks slice.
|
||||
chunk := EmptyMinSpanChunksSlice(params)
|
||||
chunk := EmptyMinSpanChunksSlice(defaultParams)
|
||||
chunkIdx := uint64(0)
|
||||
currentEpoch := types.Epoch(3)
|
||||
validatorIdx := types.ValidatorIndex(0)
|
||||
@@ -537,9 +537,9 @@ func Test_applyAttestationForValidator_MinSpanChunk(t *testing.T) {
|
||||
func Test_applyAttestationForValidator_MaxSpanChunk(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
slasherDB := dbtest.SetupSlasherDB(t)
|
||||
params := DefaultParams()
|
||||
defaultParams := DefaultParams()
|
||||
srv := &Service{
|
||||
params: params,
|
||||
params: defaultParams,
|
||||
serviceCfg: &ServiceConfig{
|
||||
Database: slasherDB,
|
||||
StateNotifier: &mock.MockStateNotifier{},
|
||||
@@ -547,7 +547,7 @@ func Test_applyAttestationForValidator_MaxSpanChunk(t *testing.T) {
|
||||
latestEpochWrittenForValidator: map[types.ValidatorIndex]types.Epoch{},
|
||||
}
|
||||
// We initialize an empty chunks slice.
|
||||
chunk := EmptyMaxSpanChunksSlice(params)
|
||||
chunk := EmptyMaxSpanChunksSlice(defaultParams)
|
||||
chunkIdx := uint64(0)
|
||||
currentEpoch := types.Epoch(3)
|
||||
validatorIdx := types.ValidatorIndex(0)
|
||||
@@ -687,7 +687,7 @@ func testLoadChunks(t *testing.T, kind slashertypes.ChunkKind) {
|
||||
ctx := context.Background()
|
||||
|
||||
// Check if the chunk at chunk index already exists in-memory.
|
||||
params := DefaultParams()
|
||||
defaultParams := DefaultParams()
|
||||
s := &Service{
|
||||
params: DefaultParams(),
|
||||
serviceCfg: &ServiceConfig{
|
||||
@@ -699,9 +699,9 @@ func testLoadChunks(t *testing.T, kind slashertypes.ChunkKind) {
|
||||
// is initialized as an empty chunk.
|
||||
var emptyChunk Chunker
|
||||
if kind == slashertypes.MinSpan {
|
||||
emptyChunk = EmptyMinSpanChunksSlice(params)
|
||||
emptyChunk = EmptyMinSpanChunksSlice(defaultParams)
|
||||
} else {
|
||||
emptyChunk = EmptyMaxSpanChunksSlice(params)
|
||||
emptyChunk = EmptyMaxSpanChunksSlice(defaultParams)
|
||||
}
|
||||
chunkIdx := uint64(2)
|
||||
received, err := s.loadChunks(ctx, &chunkUpdateArgs{
|
||||
@@ -717,15 +717,15 @@ func testLoadChunks(t *testing.T, kind slashertypes.ChunkKind) {
|
||||
// Save chunks to disk, then load them properly from disk.
|
||||
var existingChunk Chunker
|
||||
if kind == slashertypes.MinSpan {
|
||||
existingChunk = EmptyMinSpanChunksSlice(params)
|
||||
existingChunk = EmptyMinSpanChunksSlice(defaultParams)
|
||||
} else {
|
||||
existingChunk = EmptyMaxSpanChunksSlice(params)
|
||||
existingChunk = EmptyMaxSpanChunksSlice(defaultParams)
|
||||
}
|
||||
validatorIdx := types.ValidatorIndex(0)
|
||||
epochInChunk := types.Epoch(0)
|
||||
targetEpoch := types.Epoch(2)
|
||||
err = setChunkDataAtEpoch(
|
||||
params,
|
||||
defaultParams,
|
||||
existingChunk.Chunk(),
|
||||
validatorIdx,
|
||||
epochInChunk,
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/prysmaticlabs/go-bitfield"
|
||||
state_native "github.com/prysmaticlabs/prysm/beacon-chain/state/state-native"
|
||||
statenative "github.com/prysmaticlabs/prysm/beacon-chain/state/state-native"
|
||||
v1 "github.com/prysmaticlabs/prysm/beacon-chain/state/v1"
|
||||
v2 "github.com/prysmaticlabs/prysm/beacon-chain/state/v2"
|
||||
v3 "github.com/prysmaticlabs/prysm/beacon-chain/state/v3"
|
||||
@@ -49,11 +49,11 @@ func TestComputeFieldRootsWithHasher_Phase0(t *testing.T) {
|
||||
require.Equal(t, true, ok)
|
||||
protoState, ok := v1State.InnerStateUnsafe().(*ethpb.BeaconState)
|
||||
require.Equal(t, true, ok)
|
||||
initState, err := state_native.InitializeFromProtoPhase0(protoState)
|
||||
initState, err := statenative.InitializeFromProtoPhase0(protoState)
|
||||
require.NoError(t, err)
|
||||
s, ok := initState.(*state_native.BeaconState)
|
||||
s, ok := initState.(*statenative.BeaconState)
|
||||
require.Equal(t, true, ok)
|
||||
root, err := state_native.ComputeFieldRootsWithHasher(context.Background(), s)
|
||||
root, err := statenative.ComputeFieldRootsWithHasher(context.Background(), s)
|
||||
require.NoError(t, err)
|
||||
expected := [][]byte{
|
||||
{0x7b, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
|
||||
@@ -115,12 +115,12 @@ func TestComputeFieldRootsWithHasher_Altair(t *testing.T) {
|
||||
require.Equal(t, true, ok)
|
||||
protoState, ok := v1State.InnerStateUnsafe().(*ethpb.BeaconStateAltair)
|
||||
require.Equal(t, true, ok)
|
||||
initState, err := state_native.InitializeFromProtoAltair(protoState)
|
||||
initState, err := statenative.InitializeFromProtoAltair(protoState)
|
||||
require.NoError(t, err)
|
||||
s, ok := initState.(*state_native.BeaconState)
|
||||
s, ok := initState.(*statenative.BeaconState)
|
||||
require.Equal(t, true, ok)
|
||||
|
||||
root, err := state_native.ComputeFieldRootsWithHasher(context.Background(), s)
|
||||
root, err := statenative.ComputeFieldRootsWithHasher(context.Background(), s)
|
||||
require.NoError(t, err)
|
||||
expected := [][]byte{
|
||||
{0x7b, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
|
||||
@@ -186,12 +186,12 @@ func TestComputeFieldRootsWithHasher_Bellatrix(t *testing.T) {
|
||||
require.Equal(t, true, ok)
|
||||
protoState, ok := v1State.InnerStateUnsafe().(*ethpb.BeaconStateBellatrix)
|
||||
require.Equal(t, true, ok)
|
||||
initState, err := state_native.InitializeFromProtoBellatrix(protoState)
|
||||
initState, err := statenative.InitializeFromProtoBellatrix(protoState)
|
||||
require.NoError(t, err)
|
||||
s, ok := initState.(*state_native.BeaconState)
|
||||
s, ok := initState.(*statenative.BeaconState)
|
||||
require.Equal(t, true, ok)
|
||||
|
||||
root, err := state_native.ComputeFieldRootsWithHasher(context.Background(), s)
|
||||
root, err := statenative.ComputeFieldRootsWithHasher(context.Background(), s)
|
||||
require.NoError(t, err)
|
||||
expected := [][]byte{
|
||||
{0x7b, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
|
||||
|
||||
@@ -67,8 +67,7 @@ func TestReadOnlyValidator_WithdrawalCredentials(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestReadOnlyValidator_Slashed(t *testing.T) {
|
||||
slashed := true
|
||||
v, err := statenative.NewValidator(ðpb.Validator{Slashed: slashed})
|
||||
v, err := statenative.NewValidator(ðpb.Validator{Slashed: true})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, slashed, v.Slashed())
|
||||
assert.Equal(t, true, v.Slashed())
|
||||
}
|
||||
|
||||
@@ -228,7 +228,7 @@ func ReplayProcessSlots(ctx context.Context, state state.BeaconState, slot types
|
||||
}
|
||||
|
||||
if prysmtime.CanUpgradeToBellatrix(state.Slot()) {
|
||||
state, err = execution.UpgradeToBellatrix(ctx, state)
|
||||
state, err = execution.UpgradeToBellatrix(state)
|
||||
if err != nil {
|
||||
tracing.AnnotateError(span, err)
|
||||
return nil, err
|
||||
|
||||
@@ -89,13 +89,6 @@ func VerifyBeaconStateMarshalSSZNilState(t *testing.T, factory getState, clear c
|
||||
require.ErrorContains(t, "nil beacon state", err)
|
||||
}
|
||||
|
||||
func VerifyBeaconStateMarshalSSZNilStateNative(t *testing.T, factory getState) {
|
||||
s, err := factory()
|
||||
require.NoError(t, err)
|
||||
_, err = s.MarshalSSZ()
|
||||
require.ErrorContains(t, "nil beacon state", err)
|
||||
}
|
||||
|
||||
func VerifyBeaconStateValidatorByPubkey(t *testing.T, factory getState) {
|
||||
keyCreator := func(input []byte) [fieldparams.BLSPubkeyLength]byte {
|
||||
nKey := [fieldparams.BLSPubkeyLength]byte{}
|
||||
|
||||
@@ -67,8 +67,7 @@ func TestReadOnlyValidator_WithdrawalCredentials(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestReadOnlyValidator_Slashed(t *testing.T) {
|
||||
slashed := true
|
||||
v, err := v1.NewValidator(ðpb.Validator{Slashed: slashed})
|
||||
v, err := v1.NewValidator(ðpb.Validator{Slashed: true})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, slashed, v.Slashed())
|
||||
assert.Equal(t, true, v.Slashed())
|
||||
}
|
||||
|
||||
@@ -42,12 +42,12 @@ func (*BeaconState) SetCurrentParticipationBits(_ []byte) error {
|
||||
}
|
||||
|
||||
// ModifyPreviousParticipationBits is not supported for phase 0 beacon state.
|
||||
func (b *BeaconState) ModifyPreviousParticipationBits(mutator func(val []byte) ([]byte, error)) error {
|
||||
func (b *BeaconState) ModifyPreviousParticipationBits(_ func(val []byte) ([]byte, error)) error {
|
||||
return errors.New("ModifyPreviousParticipationBits is not supported for phase 0 beacon state")
|
||||
}
|
||||
|
||||
// ModifyCurrentParticipationBits is not supported for phase 0 beacon state.
|
||||
func (b *BeaconState) ModifyCurrentParticipationBits(mutator func(val []byte) ([]byte, error)) error {
|
||||
func (b *BeaconState) ModifyCurrentParticipationBits(_ func(val []byte) ([]byte, error)) error {
|
||||
return errors.New("ModifyCurrentParticipationBits is not supported for phase 0 beacon state")
|
||||
}
|
||||
|
||||
@@ -57,6 +57,6 @@ func (*BeaconState) SetInactivityScores(_ []uint64) error {
|
||||
}
|
||||
|
||||
// SetLatestExecutionPayloadHeader is not supported for phase 0 beacon state.
|
||||
func (*BeaconState) SetLatestExecutionPayloadHeader(val *enginev1.ExecutionPayloadHeader) error {
|
||||
func (*BeaconState) SetLatestExecutionPayloadHeader(_ *enginev1.ExecutionPayloadHeader) error {
|
||||
return errors.New("SetLatestExecutionPayloadHeader is not supported for phase 0 beacon state")
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ func TestService_CheckForNextEpochFork(t *testing.T) {
|
||||
{
|
||||
name: "no fork in the next epoch",
|
||||
svcCreator: func(t *testing.T) *Service {
|
||||
p2p := p2ptest.NewTestP2P(t)
|
||||
peer2peer := p2ptest.NewTestP2P(t)
|
||||
chainService := &mockChain.ChainService{
|
||||
Genesis: time.Now().Add(time.Duration(-params.BeaconConfig().SlotsPerEpoch.Mul(uint64(params.BeaconConfig().SlotsPerEpoch))) * time.Second),
|
||||
ValidatorsRoot: [32]byte{'A'},
|
||||
@@ -38,7 +38,7 @@ func TestService_CheckForNextEpochFork(t *testing.T) {
|
||||
ctx: ctx,
|
||||
cancel: cancel,
|
||||
cfg: &config{
|
||||
p2p: p2p,
|
||||
p2p: peer2peer,
|
||||
chain: chainService,
|
||||
stateNotifier: chainService.StateNotifier(),
|
||||
initialSync: &mockSync.Sync{IsSyncing: false},
|
||||
@@ -57,7 +57,7 @@ func TestService_CheckForNextEpochFork(t *testing.T) {
|
||||
{
|
||||
name: "altair fork in the next epoch",
|
||||
svcCreator: func(t *testing.T) *Service {
|
||||
p2p := p2ptest.NewTestP2P(t)
|
||||
peer2peer := p2ptest.NewTestP2P(t)
|
||||
chainService := &mockChain.ChainService{
|
||||
Genesis: time.Now().Add(-4 * oneEpoch()),
|
||||
ValidatorsRoot: [32]byte{'A'},
|
||||
@@ -71,7 +71,7 @@ func TestService_CheckForNextEpochFork(t *testing.T) {
|
||||
ctx: ctx,
|
||||
cancel: cancel,
|
||||
cfg: &config{
|
||||
p2p: p2p,
|
||||
p2p: peer2peer,
|
||||
chain: chainService,
|
||||
stateNotifier: chainService.StateNotifier(),
|
||||
initialSync: &mockSync.Sync{IsSyncing: false},
|
||||
@@ -100,7 +100,7 @@ func TestService_CheckForNextEpochFork(t *testing.T) {
|
||||
{
|
||||
name: "bellatrix fork in the next epoch",
|
||||
svcCreator: func(t *testing.T) *Service {
|
||||
p2p := p2ptest.NewTestP2P(t)
|
||||
peer2peer := p2ptest.NewTestP2P(t)
|
||||
chainService := &mockChain.ChainService{
|
||||
Genesis: time.Now().Add(-4 * oneEpoch()),
|
||||
ValidatorsRoot: [32]byte{'A'},
|
||||
@@ -115,7 +115,7 @@ func TestService_CheckForNextEpochFork(t *testing.T) {
|
||||
ctx: ctx,
|
||||
cancel: cancel,
|
||||
cfg: &config{
|
||||
p2p: p2p,
|
||||
p2p: peer2peer,
|
||||
chain: chainService,
|
||||
stateNotifier: chainService.StateNotifier(),
|
||||
initialSync: &mockSync.Sync{IsSyncing: false},
|
||||
@@ -162,7 +162,7 @@ func TestService_CheckForPreviousEpochFork(t *testing.T) {
|
||||
{
|
||||
name: "no fork in the previous epoch",
|
||||
svcCreator: func(t *testing.T) *Service {
|
||||
p2p := p2ptest.NewTestP2P(t)
|
||||
peer2peer := p2ptest.NewTestP2P(t)
|
||||
chainService := &mockChain.ChainService{
|
||||
Genesis: time.Now().Add(-oneEpoch()),
|
||||
ValidatorsRoot: [32]byte{'A'},
|
||||
@@ -172,7 +172,7 @@ func TestService_CheckForPreviousEpochFork(t *testing.T) {
|
||||
ctx: ctx,
|
||||
cancel: cancel,
|
||||
cfg: &config{
|
||||
p2p: p2p,
|
||||
p2p: peer2peer,
|
||||
chain: chainService,
|
||||
stateNotifier: chainService.StateNotifier(),
|
||||
initialSync: &mockSync.Sync{IsSyncing: false},
|
||||
@@ -202,7 +202,7 @@ func TestService_CheckForPreviousEpochFork(t *testing.T) {
|
||||
{
|
||||
name: "altair fork in the previous epoch",
|
||||
svcCreator: func(t *testing.T) *Service {
|
||||
p2p := p2ptest.NewTestP2P(t)
|
||||
peer2peer := p2ptest.NewTestP2P(t)
|
||||
chainService := &mockChain.ChainService{
|
||||
Genesis: time.Now().Add(-4 * oneEpoch()),
|
||||
ValidatorsRoot: [32]byte{'A'},
|
||||
@@ -216,7 +216,7 @@ func TestService_CheckForPreviousEpochFork(t *testing.T) {
|
||||
ctx: ctx,
|
||||
cancel: cancel,
|
||||
cfg: &config{
|
||||
p2p: p2p,
|
||||
p2p: peer2peer,
|
||||
chain: chainService,
|
||||
stateNotifier: chainService.StateNotifier(),
|
||||
initialSync: &mockSync.Sync{IsSyncing: false},
|
||||
@@ -276,7 +276,7 @@ func TestService_CheckForPreviousEpochFork(t *testing.T) {
|
||||
{
|
||||
name: "bellatrix fork in the previous epoch",
|
||||
svcCreator: func(t *testing.T) *Service {
|
||||
p2p := p2ptest.NewTestP2P(t)
|
||||
peer2peer := p2ptest.NewTestP2P(t)
|
||||
chainService := &mockChain.ChainService{
|
||||
Genesis: time.Now().Add(-4 * oneEpoch()),
|
||||
ValidatorsRoot: [32]byte{'A'},
|
||||
@@ -291,7 +291,7 @@ func TestService_CheckForPreviousEpochFork(t *testing.T) {
|
||||
ctx: ctx,
|
||||
cancel: cancel,
|
||||
cfg: &config{
|
||||
p2p: p2p,
|
||||
p2p: peer2peer,
|
||||
chain: chainService,
|
||||
stateNotifier: chainService.StateNotifier(),
|
||||
initialSync: &mockSync.Sync{IsSyncing: false},
|
||||
|
||||
@@ -343,14 +343,14 @@ func TestBlocksFetcher_RoundRobin(t *testing.T) {
|
||||
return blocks[i].Block().Slot() < blocks[j].Block().Slot()
|
||||
})
|
||||
|
||||
slots := make([]types.Slot, len(blocks))
|
||||
ss := make([]types.Slot, len(blocks))
|
||||
for i, block := range blocks {
|
||||
slots[i] = block.Block().Slot()
|
||||
ss[i] = block.Block().Slot()
|
||||
}
|
||||
|
||||
log.WithFields(logrus.Fields{
|
||||
"blocksLen": len(blocks),
|
||||
"slots": slots,
|
||||
"slots": ss,
|
||||
}).Debug("Finished block fetching")
|
||||
|
||||
if len(blocks) > int(maxExpectedBlocks) {
|
||||
|
||||
@@ -432,7 +432,7 @@ func (q *blocksQueue) onProcessSkippedEvent(ctx context.Context) eventHandlerFn
|
||||
delete(q.staleEpochs, slots.ToEpoch(startSlot))
|
||||
fork, err := q.blocksFetcher.findFork(ctx, startSlot)
|
||||
if err == nil {
|
||||
return stateSkipped, q.resetFromFork(ctx, fork)
|
||||
return stateSkipped, q.resetFromFork(fork)
|
||||
}
|
||||
log.WithFields(logrus.Fields{
|
||||
"epoch": slots.ToEpoch(startSlot),
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
// resetWithBlocks removes all state machines, then re-adds enough machines to contain all provided
|
||||
// blocks (machines are set into stateDataParsed state, so that their content is immediately
|
||||
// consumable). It is assumed that blocks come in an ascending order.
|
||||
func (q *blocksQueue) resetFromFork(ctx context.Context, fork *forkData) error {
|
||||
func (q *blocksQueue) resetFromFork(fork *forkData) error {
|
||||
if fork == nil {
|
||||
return errors.New("nil fork data")
|
||||
}
|
||||
|
||||
@@ -188,10 +188,10 @@ func connectPeer(t *testing.T, host *p2pt.TestP2P, datum *peerData, peerStatus *
|
||||
}
|
||||
|
||||
// Determine the correct subset of blocks to return as dictated by the test scenario.
|
||||
slots := slice.IntersectionSlot(datum.blocks, requestedBlocks)
|
||||
ss := slice.IntersectionSlot(datum.blocks, requestedBlocks)
|
||||
|
||||
ret := make([]*ethpb.SignedBeaconBlock, 0)
|
||||
for _, slot := range slots {
|
||||
for _, slot := range ss {
|
||||
if (slot - req.StartSlot).Mod(req.Step) != 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -57,16 +57,16 @@ func (s *Service) processPendingBlocks(ctx context.Context) error {
|
||||
if err := s.validatePendingSlots(); err != nil {
|
||||
return errors.Wrap(err, "could not validate pending slots")
|
||||
}
|
||||
slots := s.sortedPendingSlots()
|
||||
ss := s.sortedPendingSlots()
|
||||
var parentRoots [][32]byte
|
||||
|
||||
span.AddAttributes(
|
||||
trace.Int64Attribute("numSlots", int64(len(slots))),
|
||||
trace.Int64Attribute("numSlots", int64(len(ss))),
|
||||
trace.Int64Attribute("numPeers", int64(len(pids))),
|
||||
)
|
||||
|
||||
randGen := rand.NewGenerator()
|
||||
for _, slot := range slots {
|
||||
for _, slot := range ss {
|
||||
// process the blocks during their respective slot.
|
||||
// otherwise wait for the right slot to process the block.
|
||||
if slot > s.cfg.chain.CurrentSlot() {
|
||||
@@ -257,15 +257,15 @@ func (s *Service) sortedPendingSlots() []types.Slot {
|
||||
|
||||
items := s.slotToPendingBlocks.Items()
|
||||
|
||||
slots := make([]types.Slot, 0, len(items))
|
||||
ss := make([]types.Slot, 0, len(items))
|
||||
for k := range items {
|
||||
slot := cacheKeyToSlot(k)
|
||||
slots = append(slots, slot)
|
||||
ss = append(ss, slot)
|
||||
}
|
||||
sort.Slice(slots, func(i, j int) bool {
|
||||
return slots[i] < slots[j]
|
||||
sort.Slice(ss, func(i, j int) bool {
|
||||
return ss[i] < ss[j]
|
||||
})
|
||||
return slots
|
||||
return ss
|
||||
}
|
||||
|
||||
// validatePendingSlots validates the pending blocks
|
||||
|
||||
@@ -122,11 +122,11 @@ func TestMetadataRPCHandler_SendsMetadata(t *testing.T) {
|
||||
assert.NoError(t, r2.metaDataHandler(context.Background(), new(interface{}), stream))
|
||||
})
|
||||
|
||||
metadata, err := r.sendMetaDataRequest(context.Background(), p2.BHost.ID())
|
||||
md, err := r.sendMetaDataRequest(context.Background(), p2.BHost.ID())
|
||||
assert.NoError(t, err)
|
||||
|
||||
if !equality.DeepEqual(metadata.InnerObject(), p2.LocalMetadata.InnerObject()) {
|
||||
t.Fatalf("MetadataV0 unequal, received %v but wanted %v", metadata, p2.LocalMetadata)
|
||||
if !equality.DeepEqual(md.InnerObject(), p2.LocalMetadata.InnerObject()) {
|
||||
t.Fatalf("MetadataV0 unequal, received %v but wanted %v", md, p2.LocalMetadata)
|
||||
}
|
||||
|
||||
if util.WaitTimeout(&wg, 1*time.Second) {
|
||||
@@ -210,11 +210,11 @@ func TestMetadataRPCHandler_SendsMetadataAltair(t *testing.T) {
|
||||
assert.NoError(t, r2.metaDataHandler(context.Background(), new(interface{}), stream))
|
||||
})
|
||||
|
||||
metadata, err := r.sendMetaDataRequest(context.Background(), p2.BHost.ID())
|
||||
md, err := r.sendMetaDataRequest(context.Background(), p2.BHost.ID())
|
||||
assert.NoError(t, err)
|
||||
|
||||
if !equality.DeepEqual(metadata.InnerObject(), p2.LocalMetadata.InnerObject()) {
|
||||
t.Fatalf("MetadataV1 unequal, received %v but wanted %v", metadata, p2.LocalMetadata)
|
||||
if !equality.DeepEqual(md.InnerObject(), p2.LocalMetadata.InnerObject()) {
|
||||
t.Fatalf("MetadataV1 unequal, received %v but wanted %v", md, p2.LocalMetadata)
|
||||
}
|
||||
|
||||
if util.WaitTimeout(&wg, 1*time.Second) {
|
||||
|
||||
@@ -237,10 +237,10 @@ func (s *Service) registerHandlers() {
|
||||
defer stateSub.Unsubscribe()
|
||||
for {
|
||||
select {
|
||||
case event := <-stateChannel:
|
||||
switch event.Type {
|
||||
case e := <-stateChannel:
|
||||
switch e.Type {
|
||||
case statefeed.Initialized:
|
||||
data, ok := event.Data.(*statefeed.InitializedData)
|
||||
data, ok := e.Data.(*statefeed.InitializedData)
|
||||
if !ok {
|
||||
log.Error("Event feed data is not type *statefeed.InitializedData")
|
||||
return
|
||||
@@ -259,7 +259,7 @@ func (s *Service) registerHandlers() {
|
||||
s.markForChainStart()
|
||||
}()
|
||||
case statefeed.Synced:
|
||||
_, ok := event.Data.(*statefeed.SyncedData)
|
||||
_, ok := e.Data.(*statefeed.SyncedData)
|
||||
if !ok {
|
||||
log.Error("Event feed data is not type *statefeed.SyncedData")
|
||||
return
|
||||
|
||||
@@ -680,14 +680,14 @@ func (s *Service) filterNeededPeers(pids []peer.ID) []peer.ID {
|
||||
|
||||
for _, sub := range wantedSubs {
|
||||
subnetTopic := fmt.Sprintf(topic, digest, sub) + s.cfg.p2p.Encoding().ProtocolSuffix()
|
||||
peers := s.cfg.p2p.PubSub().ListPeers(subnetTopic)
|
||||
if len(peers) > flags.Get().MinimumPeersPerSubnet {
|
||||
ps := s.cfg.p2p.PubSub().ListPeers(subnetTopic)
|
||||
if len(ps) > flags.Get().MinimumPeersPerSubnet {
|
||||
// In the event we have more than the minimum, we can
|
||||
// mark the remaining as viable for pruning.
|
||||
peers = peers[:flags.Get().MinimumPeersPerSubnet]
|
||||
ps = ps[:flags.Get().MinimumPeersPerSubnet]
|
||||
}
|
||||
// Add peer to peer map.
|
||||
for _, p := range peers {
|
||||
for _, p := range ps {
|
||||
// Even if the peer id has
|
||||
// already been seen we still set
|
||||
// it, as the outcome is the same.
|
||||
|
||||
@@ -26,12 +26,12 @@ import (
|
||||
)
|
||||
|
||||
func setupValidAttesterSlashing(t *testing.T) (*ethpb.AttesterSlashing, state.BeaconState) {
|
||||
state, privKeys := util.DeterministicGenesisState(t, 5)
|
||||
vals := state.Validators()
|
||||
s, privKeys := util.DeterministicGenesisState(t, 5)
|
||||
vals := s.Validators()
|
||||
for _, vv := range vals {
|
||||
vv.WithdrawableEpoch = types.Epoch(1 * params.BeaconConfig().SlotsPerEpoch)
|
||||
}
|
||||
require.NoError(t, state.SetValidators(vals))
|
||||
require.NoError(t, s.SetValidators(vals))
|
||||
|
||||
att1 := util.HydrateIndexedAttestation(ðpb.IndexedAttestation{
|
||||
Data: ðpb.AttestationData{
|
||||
@@ -39,7 +39,7 @@ func setupValidAttesterSlashing(t *testing.T) (*ethpb.AttesterSlashing, state.Be
|
||||
},
|
||||
AttestingIndices: []uint64{0, 1},
|
||||
})
|
||||
domain, err := signing.Domain(state.Fork(), 0, params.BeaconConfig().DomainBeaconAttester, state.GenesisValidatorsRoot())
|
||||
domain, err := signing.Domain(s.Fork(), 0, params.BeaconConfig().DomainBeaconAttester, s.GenesisValidatorsRoot())
|
||||
require.NoError(t, err)
|
||||
hashTreeRoot, err := signing.ComputeSigningRoot(att1.Data, domain)
|
||||
assert.NoError(t, err)
|
||||
@@ -64,13 +64,13 @@ func setupValidAttesterSlashing(t *testing.T) (*ethpb.AttesterSlashing, state.Be
|
||||
}
|
||||
|
||||
currentSlot := 2 * params.BeaconConfig().SlotsPerEpoch
|
||||
require.NoError(t, state.SetSlot(currentSlot))
|
||||
require.NoError(t, s.SetSlot(currentSlot))
|
||||
|
||||
b := make([]byte, 32)
|
||||
_, err = rand.Read(b)
|
||||
require.NoError(t, err)
|
||||
|
||||
return slashing, state
|
||||
return slashing, s
|
||||
}
|
||||
|
||||
func TestValidateAttesterSlashing_ValidSlashing(t *testing.T) {
|
||||
@@ -178,7 +178,7 @@ func TestValidateAttesterSlashing_CanFilter(t *testing.T) {
|
||||
func TestValidateAttesterSlashing_ContextTimeout(t *testing.T) {
|
||||
p := p2ptest.NewTestP2P(t)
|
||||
|
||||
slashing, state := setupValidAttesterSlashing(t)
|
||||
slashing, s := setupValidAttesterSlashing(t)
|
||||
slashing.Attestation_1.Data.Target.Epoch = 100000000
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond)
|
||||
@@ -187,7 +187,7 @@ func TestValidateAttesterSlashing_ContextTimeout(t *testing.T) {
|
||||
r := &Service{
|
||||
cfg: &config{
|
||||
p2p: p,
|
||||
chain: &mock.ChainService{State: state},
|
||||
chain: &mock.ChainService{State: s},
|
||||
initialSync: &mockSync.Sync{IsSyncing: false},
|
||||
},
|
||||
seenAttesterSlashingCache: make(map[uint64]bool),
|
||||
|
||||
@@ -45,7 +45,7 @@ func setupValidProposerSlashing(t *testing.T) (*ethpb.ProposerSlashing, state.Be
|
||||
}
|
||||
|
||||
currentSlot := types.Slot(0)
|
||||
state, err := v1.InitializeFromProto(ðpb.BeaconState{
|
||||
st, err := v1.InitializeFromProto(ðpb.BeaconState{
|
||||
Validators: validators,
|
||||
Slot: currentSlot,
|
||||
Balances: validatorBalances,
|
||||
@@ -76,7 +76,7 @@ func setupValidProposerSlashing(t *testing.T) (*ethpb.ProposerSlashing, state.Be
|
||||
BodyRoot: someRoot[:],
|
||||
},
|
||||
}
|
||||
header1.Signature, err = signing.ComputeDomainAndSign(state, coreTime.CurrentEpoch(state), header1.Header, params.BeaconConfig().DomainBeaconProposer, privKey)
|
||||
header1.Signature, err = signing.ComputeDomainAndSign(st, coreTime.CurrentEpoch(st), header1.Header, params.BeaconConfig().DomainBeaconProposer, privKey)
|
||||
require.NoError(t, err)
|
||||
|
||||
header2 := ðpb.SignedBeaconBlockHeader{
|
||||
@@ -88,23 +88,23 @@ func setupValidProposerSlashing(t *testing.T) (*ethpb.ProposerSlashing, state.Be
|
||||
BodyRoot: someRoot2[:],
|
||||
},
|
||||
}
|
||||
header2.Signature, err = signing.ComputeDomainAndSign(state, coreTime.CurrentEpoch(state), header2.Header, params.BeaconConfig().DomainBeaconProposer, privKey)
|
||||
header2.Signature, err = signing.ComputeDomainAndSign(st, coreTime.CurrentEpoch(st), header2.Header, params.BeaconConfig().DomainBeaconProposer, privKey)
|
||||
require.NoError(t, err)
|
||||
|
||||
slashing := ðpb.ProposerSlashing{
|
||||
Header_1: header1,
|
||||
Header_2: header2,
|
||||
}
|
||||
val, err := state.ValidatorAtIndex(1)
|
||||
val, err := st.ValidatorAtIndex(1)
|
||||
require.NoError(t, err)
|
||||
val.PublicKey = privKey.PublicKey().Marshal()
|
||||
require.NoError(t, state.UpdateValidatorAtIndex(1, val))
|
||||
require.NoError(t, st.UpdateValidatorAtIndex(1, val))
|
||||
|
||||
b := make([]byte, 32)
|
||||
_, err = rand.Read(b)
|
||||
require.NoError(t, err)
|
||||
|
||||
return slashing, state
|
||||
return slashing, st
|
||||
}
|
||||
|
||||
func TestValidateProposerSlashing_ValidSlashing(t *testing.T) {
|
||||
@@ -146,11 +146,11 @@ func TestValidateProposerSlashing_ValidSlashing(t *testing.T) {
|
||||
func TestValidateProposerSlashing_ContextTimeout(t *testing.T) {
|
||||
p := p2ptest.NewTestP2P(t)
|
||||
|
||||
slashing, state := setupValidProposerSlashing(t)
|
||||
slashing, st := setupValidProposerSlashing(t)
|
||||
slashing.Header_1.Header.Slot = 100000000
|
||||
err := state.SetJustificationBits(bitfield.Bitvector4{0x0F}) // 0b1111
|
||||
err := st.SetJustificationBits(bitfield.Bitvector4{0x0F}) // 0b1111
|
||||
require.NoError(t, err)
|
||||
err = state.SetPreviousJustifiedCheckpoint(ðpb.Checkpoint{Epoch: 0, Root: []byte{}})
|
||||
err = st.SetPreviousJustifiedCheckpoint(ðpb.Checkpoint{Epoch: 0, Root: []byte{}})
|
||||
require.NoError(t, err)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond)
|
||||
defer cancel()
|
||||
@@ -158,7 +158,7 @@ func TestValidateProposerSlashing_ContextTimeout(t *testing.T) {
|
||||
r := &Service{
|
||||
cfg: &config{
|
||||
p2p: p,
|
||||
chain: &mock.ChainService{State: state},
|
||||
chain: &mock.ChainService{State: st},
|
||||
initialSync: &mockSync.Sync{IsSyncing: false},
|
||||
},
|
||||
seenProposerSlashingCache: lruwrpr.New(10),
|
||||
|
||||
@@ -11,10 +11,10 @@ import (
|
||||
"github.com/golang/snappy"
|
||||
"github.com/libp2p/go-libp2p-core/peer"
|
||||
pubsub "github.com/libp2p/go-libp2p-pubsub"
|
||||
pubsub_pb "github.com/libp2p/go-libp2p-pubsub/pb"
|
||||
pubsubpb "github.com/libp2p/go-libp2p-pubsub/pb"
|
||||
mockChain "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/signing"
|
||||
testingDB "github.com/prysmaticlabs/prysm/beacon-chain/db/testing"
|
||||
testingdb "github.com/prysmaticlabs/prysm/beacon-chain/db/testing"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/p2p"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/p2p/encoder"
|
||||
mockp2p "github.com/prysmaticlabs/prysm/beacon-chain/p2p/testing"
|
||||
@@ -31,7 +31,7 @@ import (
|
||||
)
|
||||
|
||||
func TestService_ValidateSyncCommitteeMessage(t *testing.T) {
|
||||
beaconDB := testingDB.SetupDB(t)
|
||||
beaconDB := testingdb.SetupDB(t)
|
||||
headRoot, keys := fillUpBlocksAndState(context.Background(), t, beaconDB)
|
||||
defaultTopic := p2p.SyncCommitteeSubnetTopicFormat
|
||||
fakeDigest := []byte{0xAB, 0x00, 0xCC, 0x9E}
|
||||
@@ -417,7 +417,7 @@ func TestService_ValidateSyncCommitteeMessage(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
marshalledObj = snappy.Encode(nil, marshalledObj)
|
||||
msg := &pubsub.Message{
|
||||
Message: &pubsub_pb.Message{
|
||||
Message: &pubsubpb.Message{
|
||||
Data: marshalledObj,
|
||||
Topic: &tt.args.topic,
|
||||
},
|
||||
@@ -583,7 +583,7 @@ func TestValidateSyncCommitteeMessage_Optimistic(t *testing.T) {
|
||||
|
||||
topic := p2p.GossipTypeMapping[reflect.TypeOf(slashing)]
|
||||
msg := &pubsub.Message{
|
||||
Message: &pubsub_pb.Message{
|
||||
Message: &pubsubpb.Message{
|
||||
Data: buf.Bytes(),
|
||||
Topic: &topic,
|
||||
},
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
"github.com/golang/snappy"
|
||||
"github.com/libp2p/go-libp2p-core/peer"
|
||||
pubsub "github.com/libp2p/go-libp2p-pubsub"
|
||||
pubsub_pb "github.com/libp2p/go-libp2p-pubsub/pb"
|
||||
pubsubpb "github.com/libp2p/go-libp2p-pubsub/pb"
|
||||
"github.com/prysmaticlabs/go-bitfield"
|
||||
mockChain "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/altair"
|
||||
@@ -20,7 +20,7 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/signing"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/transition"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/db"
|
||||
testingDB "github.com/prysmaticlabs/prysm/beacon-chain/db/testing"
|
||||
testingdb "github.com/prysmaticlabs/prysm/beacon-chain/db/testing"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/p2p"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/p2p/encoder"
|
||||
mockp2p "github.com/prysmaticlabs/prysm/beacon-chain/p2p/testing"
|
||||
@@ -41,8 +41,8 @@ import (
|
||||
)
|
||||
|
||||
func TestService_ValidateSyncContributionAndProof(t *testing.T) {
|
||||
db := testingDB.SetupDB(t)
|
||||
headRoot, keys := fillUpBlocksAndState(context.Background(), t, db)
|
||||
database := testingdb.SetupDB(t)
|
||||
headRoot, keys := fillUpBlocksAndState(context.Background(), t, database)
|
||||
defaultTopic := p2p.SyncContributionAndProofSubnetTopicFormat
|
||||
defaultTopic = fmt.Sprintf(defaultTopic, []byte{0xAB, 0x00, 0xCC, 0x9E})
|
||||
defaultTopic = defaultTopic + "/" + encoder.ProtocolSuffixSSZSnappy
|
||||
@@ -74,9 +74,9 @@ func TestService_ValidateSyncContributionAndProof(t *testing.T) {
|
||||
WithOperationNotifier(chainService.OperationNotifier()),
|
||||
),
|
||||
setupSvc: func(s *Service, msg *ethpb.SignedContributionAndProof) *Service {
|
||||
s.cfg.stateGen = stategen.New(db)
|
||||
s.cfg.stateGen = stategen.New(database)
|
||||
msg.Message.Contribution.BlockRoot = headRoot[:]
|
||||
s.cfg.beaconDB = db
|
||||
s.cfg.beaconDB = database
|
||||
s.initCaches()
|
||||
return s
|
||||
},
|
||||
@@ -110,9 +110,9 @@ func TestService_ValidateSyncContributionAndProof(t *testing.T) {
|
||||
WithOperationNotifier(chainService.OperationNotifier()),
|
||||
),
|
||||
setupSvc: func(s *Service, msg *ethpb.SignedContributionAndProof) *Service {
|
||||
s.cfg.stateGen = stategen.New(db)
|
||||
s.cfg.stateGen = stategen.New(database)
|
||||
msg.Message.Contribution.BlockRoot = headRoot[:]
|
||||
s.cfg.beaconDB = db
|
||||
s.cfg.beaconDB = database
|
||||
s.initCaches()
|
||||
return s
|
||||
},
|
||||
@@ -146,8 +146,8 @@ func TestService_ValidateSyncContributionAndProof(t *testing.T) {
|
||||
WithOperationNotifier(chainService.OperationNotifier()),
|
||||
),
|
||||
setupSvc: func(s *Service, msg *ethpb.SignedContributionAndProof) *Service {
|
||||
s.cfg.stateGen = stategen.New(db)
|
||||
s.cfg.beaconDB = db
|
||||
s.cfg.stateGen = stategen.New(database)
|
||||
s.cfg.beaconDB = database
|
||||
s.initCaches()
|
||||
return s
|
||||
},
|
||||
@@ -181,8 +181,8 @@ func TestService_ValidateSyncContributionAndProof(t *testing.T) {
|
||||
WithOperationNotifier(chainService.OperationNotifier()),
|
||||
),
|
||||
setupSvc: func(s *Service, msg *ethpb.SignedContributionAndProof) *Service {
|
||||
s.cfg.stateGen = stategen.New(db)
|
||||
s.cfg.beaconDB = db
|
||||
s.cfg.stateGen = stategen.New(database)
|
||||
s.cfg.beaconDB = database
|
||||
s.initCaches()
|
||||
s.cfg.chain = &mockChain.ChainService{
|
||||
ValidatorsRoot: [32]byte{'A'},
|
||||
@@ -224,8 +224,8 @@ func TestService_ValidateSyncContributionAndProof(t *testing.T) {
|
||||
WithOperationNotifier(chainService.OperationNotifier()),
|
||||
),
|
||||
setupSvc: func(s *Service, msg *ethpb.SignedContributionAndProof) *Service {
|
||||
s.cfg.stateGen = stategen.New(db)
|
||||
s.cfg.beaconDB = db
|
||||
s.cfg.stateGen = stategen.New(database)
|
||||
s.cfg.beaconDB = database
|
||||
s.initCaches()
|
||||
s.cfg.chain = &mockChain.ChainService{
|
||||
ValidatorsRoot: [32]byte{'A'},
|
||||
@@ -267,8 +267,8 @@ func TestService_ValidateSyncContributionAndProof(t *testing.T) {
|
||||
WithOperationNotifier(chainService.OperationNotifier()),
|
||||
),
|
||||
setupSvc: func(s *Service, msg *ethpb.SignedContributionAndProof) *Service {
|
||||
s.cfg.stateGen = stategen.New(db)
|
||||
s.cfg.beaconDB = db
|
||||
s.cfg.stateGen = stategen.New(database)
|
||||
s.cfg.beaconDB = database
|
||||
s.initCaches()
|
||||
s.cfg.chain = &mockChain.ChainService{
|
||||
ValidatorsRoot: [32]byte{'A'},
|
||||
@@ -311,15 +311,15 @@ func TestService_ValidateSyncContributionAndProof(t *testing.T) {
|
||||
WithOperationNotifier(chainService.OperationNotifier()),
|
||||
),
|
||||
setupSvc: func(s *Service, msg *ethpb.SignedContributionAndProof) *Service {
|
||||
s.cfg.stateGen = stategen.New(db)
|
||||
s.cfg.beaconDB = db
|
||||
s.cfg.stateGen = stategen.New(database)
|
||||
s.cfg.beaconDB = database
|
||||
s.initCaches()
|
||||
s.cfg.chain = &mockChain.ChainService{
|
||||
ValidatorsRoot: [32]byte{'A'},
|
||||
Genesis: time.Now().Add(-time.Second * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Duration(msg.Message.Contribution.Slot)),
|
||||
}
|
||||
msg.Message.Contribution.BlockRoot = headRoot[:]
|
||||
hState, err := db.State(context.Background(), headRoot)
|
||||
hState, err := database.State(context.Background(), headRoot)
|
||||
assert.NoError(t, err)
|
||||
sc, err := hState.CurrentSyncCommittee()
|
||||
assert.NoError(t, err)
|
||||
@@ -373,10 +373,10 @@ func TestService_ValidateSyncContributionAndProof(t *testing.T) {
|
||||
WithOperationNotifier(chainService.OperationNotifier()),
|
||||
),
|
||||
setupSvc: func(s *Service, msg *ethpb.SignedContributionAndProof) *Service {
|
||||
s.cfg.stateGen = stategen.New(db)
|
||||
s.cfg.beaconDB = db
|
||||
s.cfg.stateGen = stategen.New(database)
|
||||
s.cfg.beaconDB = database
|
||||
msg.Message.Contribution.BlockRoot = headRoot[:]
|
||||
hState, err := db.State(context.Background(), headRoot)
|
||||
hState, err := database.State(context.Background(), headRoot)
|
||||
assert.NoError(t, err)
|
||||
sc, err := hState.CurrentSyncCommittee()
|
||||
assert.NoError(t, err)
|
||||
@@ -438,11 +438,11 @@ func TestService_ValidateSyncContributionAndProof(t *testing.T) {
|
||||
WithOperationNotifier(chainService.OperationNotifier()),
|
||||
),
|
||||
setupSvc: func(s *Service, msg *ethpb.SignedContributionAndProof) *Service {
|
||||
s.cfg.stateGen = stategen.New(db)
|
||||
s.cfg.beaconDB = db
|
||||
s.cfg.stateGen = stategen.New(database)
|
||||
s.cfg.beaconDB = database
|
||||
s.cfg.chain = chainService
|
||||
msg.Message.Contribution.BlockRoot = headRoot[:]
|
||||
hState, err := db.State(context.Background(), headRoot)
|
||||
hState, err := database.State(context.Background(), headRoot)
|
||||
assert.NoError(t, err)
|
||||
sc, err := hState.CurrentSyncCommittee()
|
||||
assert.NoError(t, err)
|
||||
@@ -518,10 +518,10 @@ func TestService_ValidateSyncContributionAndProof(t *testing.T) {
|
||||
WithOperationNotifier(chainService.OperationNotifier()),
|
||||
),
|
||||
setupSvc: func(s *Service, msg *ethpb.SignedContributionAndProof) *Service {
|
||||
s.cfg.stateGen = stategen.New(db)
|
||||
s.cfg.beaconDB = db
|
||||
s.cfg.stateGen = stategen.New(database)
|
||||
s.cfg.beaconDB = database
|
||||
msg.Message.Contribution.BlockRoot = headRoot[:]
|
||||
hState, err := db.State(context.Background(), headRoot)
|
||||
hState, err := database.State(context.Background(), headRoot)
|
||||
assert.NoError(t, err)
|
||||
sc, err := hState.CurrentSyncCommittee()
|
||||
assert.NoError(t, err)
|
||||
@@ -600,10 +600,10 @@ func TestService_ValidateSyncContributionAndProof(t *testing.T) {
|
||||
WithOperationNotifier(chainService.OperationNotifier()),
|
||||
),
|
||||
setupSvc: func(s *Service, msg *ethpb.SignedContributionAndProof) *Service {
|
||||
s.cfg.stateGen = stategen.New(db)
|
||||
s.cfg.stateGen = stategen.New(database)
|
||||
msg.Message.Contribution.BlockRoot = headRoot[:]
|
||||
s.cfg.beaconDB = db
|
||||
hState, err := db.State(context.Background(), headRoot)
|
||||
s.cfg.beaconDB = database
|
||||
hState, err := database.State(context.Background(), headRoot)
|
||||
assert.NoError(t, err)
|
||||
sc, err := hState.CurrentSyncCommittee()
|
||||
assert.NoError(t, err)
|
||||
@@ -684,10 +684,10 @@ func TestService_ValidateSyncContributionAndProof(t *testing.T) {
|
||||
WithOperationNotifier(chainService.OperationNotifier()),
|
||||
),
|
||||
setupSvc: func(s *Service, msg *ethpb.SignedContributionAndProof) *Service {
|
||||
s.cfg.stateGen = stategen.New(db)
|
||||
s.cfg.stateGen = stategen.New(database)
|
||||
msg.Message.Contribution.BlockRoot = headRoot[:]
|
||||
s.cfg.beaconDB = db
|
||||
hState, err := db.State(context.Background(), headRoot)
|
||||
s.cfg.beaconDB = database
|
||||
hState, err := database.State(context.Background(), headRoot)
|
||||
assert.NoError(t, err)
|
||||
sc, err := hState.CurrentSyncCommittee()
|
||||
assert.NoError(t, err)
|
||||
@@ -780,10 +780,10 @@ func TestService_ValidateSyncContributionAndProof(t *testing.T) {
|
||||
WithOperationNotifier(chainService.OperationNotifier()),
|
||||
),
|
||||
setupSvc: func(s *Service, msg *ethpb.SignedContributionAndProof) *Service {
|
||||
s.cfg.stateGen = stategen.New(db)
|
||||
s.cfg.stateGen = stategen.New(database)
|
||||
msg.Message.Contribution.BlockRoot = headRoot[:]
|
||||
s.cfg.beaconDB = db
|
||||
hState, err := db.State(context.Background(), headRoot)
|
||||
s.cfg.beaconDB = database
|
||||
hState, err := database.State(context.Background(), headRoot)
|
||||
assert.NoError(t, err)
|
||||
sc, err := hState.CurrentSyncCommittee()
|
||||
assert.NoError(t, err)
|
||||
@@ -877,7 +877,7 @@ func TestService_ValidateSyncContributionAndProof(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
marshalledObj = snappy.Encode(nil, marshalledObj)
|
||||
msg := &pubsub.Message{
|
||||
Message: &pubsub_pb.Message{
|
||||
Message: &pubsubpb.Message{
|
||||
Data: marshalledObj,
|
||||
Topic: &tt.args.topic,
|
||||
},
|
||||
@@ -894,8 +894,8 @@ func TestService_ValidateSyncContributionAndProof(t *testing.T) {
|
||||
|
||||
func TestValidateSyncContributionAndProof(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
db := testingDB.SetupDB(t)
|
||||
headRoot, keys := fillUpBlocksAndState(ctx, t, db)
|
||||
database := testingdb.SetupDB(t)
|
||||
headRoot, keys := fillUpBlocksAndState(ctx, t, database)
|
||||
defaultTopic := p2p.SyncContributionAndProofSubnetTopicFormat
|
||||
defaultTopic = fmt.Sprintf(defaultTopic, []byte{0xAB, 0x00, 0xCC, 0x9E})
|
||||
defaultTopic = defaultTopic + "/" + encoder.ProtocolSuffixSSZSnappy
|
||||
@@ -927,10 +927,10 @@ func TestValidateSyncContributionAndProof(t *testing.T) {
|
||||
WithOperationNotifier(chainService.OperationNotifier()),
|
||||
)
|
||||
go s.verifierRoutine()
|
||||
s.cfg.stateGen = stategen.New(db)
|
||||
s.cfg.stateGen = stategen.New(database)
|
||||
msg.Message.Contribution.BlockRoot = headRoot[:]
|
||||
s.cfg.beaconDB = db
|
||||
hState, err := db.State(context.Background(), headRoot)
|
||||
s.cfg.beaconDB = database
|
||||
hState, err := database.State(context.Background(), headRoot)
|
||||
assert.NoError(t, err)
|
||||
sc, err := hState.CurrentSyncCommittee()
|
||||
assert.NoError(t, err)
|
||||
@@ -996,7 +996,7 @@ func TestValidateSyncContributionAndProof(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
marshalledObj = snappy.Encode(nil, marshalledObj)
|
||||
pubsubMsg := &pubsub.Message{
|
||||
Message: &pubsub_pb.Message{
|
||||
Message: &pubsubpb.Message{
|
||||
Data: marshalledObj,
|
||||
Topic: &defaultTopic,
|
||||
},
|
||||
@@ -1049,7 +1049,7 @@ func TestValidateSyncContributionAndProof_Optimistic(t *testing.T) {
|
||||
|
||||
topic := p2p.GossipTypeMapping[reflect.TypeOf(slashing)]
|
||||
msg := &pubsub.Message{
|
||||
Message: &pubsub_pb.Message{
|
||||
Message: &pubsubpb.Message{
|
||||
Data: buf.Bytes(),
|
||||
Topic: &topic,
|
||||
},
|
||||
|
||||
@@ -41,7 +41,7 @@ func setupValidExit(t *testing.T) (*ethpb.SignedVoluntaryExit, state.BeaconState
|
||||
ActivationEpoch: 0,
|
||||
},
|
||||
}
|
||||
state, err := v1.InitializeFromProto(ðpb.BeaconState{
|
||||
st, err := v1.InitializeFromProto(ðpb.BeaconState{
|
||||
Validators: registry,
|
||||
Fork: ðpb.Fork{
|
||||
CurrentVersion: params.BeaconConfig().GenesisForkVersion,
|
||||
@@ -50,24 +50,24 @@ func setupValidExit(t *testing.T) (*ethpb.SignedVoluntaryExit, state.BeaconState
|
||||
Slot: params.BeaconConfig().SlotsPerEpoch * 5,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
err = state.SetSlot(state.Slot() + params.BeaconConfig().SlotsPerEpoch.Mul(uint64(params.BeaconConfig().ShardCommitteePeriod)))
|
||||
err = st.SetSlot(st.Slot() + params.BeaconConfig().SlotsPerEpoch.Mul(uint64(params.BeaconConfig().ShardCommitteePeriod)))
|
||||
require.NoError(t, err)
|
||||
|
||||
priv, err := bls.RandKey()
|
||||
require.NoError(t, err)
|
||||
exit.Signature, err = signing.ComputeDomainAndSign(state, coreTime.CurrentEpoch(state), exit.Exit, params.BeaconConfig().DomainVoluntaryExit, priv)
|
||||
exit.Signature, err = signing.ComputeDomainAndSign(st, coreTime.CurrentEpoch(st), exit.Exit, params.BeaconConfig().DomainVoluntaryExit, priv)
|
||||
require.NoError(t, err)
|
||||
|
||||
val, err := state.ValidatorAtIndex(0)
|
||||
val, err := st.ValidatorAtIndex(0)
|
||||
require.NoError(t, err)
|
||||
val.PublicKey = priv.PublicKey().Marshal()
|
||||
require.NoError(t, state.UpdateValidatorAtIndex(0, val))
|
||||
require.NoError(t, st.UpdateValidatorAtIndex(0, val))
|
||||
|
||||
b := make([]byte, 32)
|
||||
_, err = rand.Read(b)
|
||||
require.NoError(t, err)
|
||||
|
||||
return exit, state
|
||||
return exit, st
|
||||
}
|
||||
|
||||
func TestValidateVoluntaryExit_ValidExit(t *testing.T) {
|
||||
|
||||
@@ -175,7 +175,7 @@ func TestDeleteAccounts_Noninteractive(t *testing.T) {
|
||||
// We attempt to delete the accounts specified.
|
||||
require.NoError(t, accountsDelete(cliCtx))
|
||||
|
||||
keymanager, err := local.NewKeymanager(
|
||||
km, err := local.NewKeymanager(
|
||||
cliCtx.Context,
|
||||
&local.SetupConfig{
|
||||
Wallet: w,
|
||||
@@ -183,7 +183,7 @@ func TestDeleteAccounts_Noninteractive(t *testing.T) {
|
||||
},
|
||||
)
|
||||
require.NoError(t, err)
|
||||
remainingAccounts, err := keymanager.FetchValidatingPublicKeys(cliCtx.Context)
|
||||
remainingAccounts, err := km.FetchValidatingPublicKeys(cliCtx.Context)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, len(remainingAccounts), 1)
|
||||
remainingPublicKey, err := hex.DecodeString(k3.Pubkey)
|
||||
|
||||
@@ -77,11 +77,11 @@ func TestExitAccountsCli_OK(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, accountsImport(cliCtx))
|
||||
|
||||
_, keymanager, err := walletWithKeymanager(cliCtx)
|
||||
_, km, err := walletWithKeymanager(cliCtx)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, keymanager)
|
||||
require.NotNil(t, km)
|
||||
|
||||
validatingPublicKeys, err := keymanager.FetchValidatingPublicKeys(cliCtx.Context)
|
||||
validatingPublicKeys, err := km.FetchValidatingPublicKeys(cliCtx.Context)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, validatingPublicKeys)
|
||||
|
||||
@@ -98,7 +98,7 @@ func TestExitAccountsCli_OK(t *testing.T) {
|
||||
cfg := accounts.PerformExitCfg{
|
||||
ValidatorClient: mockValidatorClient,
|
||||
NodeClient: mockNodeClient,
|
||||
Keymanager: keymanager,
|
||||
Keymanager: km,
|
||||
RawPubKeys: rawPubKeys,
|
||||
FormattedPubKeys: formattedPubKeys,
|
||||
}
|
||||
@@ -177,11 +177,11 @@ func TestExitAccountsCli_OK_AllPublicKeys(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, accountsImport(cliCtx))
|
||||
|
||||
_, keymanager, err := walletWithKeymanager(cliCtx)
|
||||
_, km, err := walletWithKeymanager(cliCtx)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, keymanager)
|
||||
require.NotNil(t, km)
|
||||
|
||||
validatingPublicKeys, err := keymanager.FetchValidatingPublicKeys(cliCtx.Context)
|
||||
validatingPublicKeys, err := km.FetchValidatingPublicKeys(cliCtx.Context)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, validatingPublicKeys)
|
||||
|
||||
@@ -198,7 +198,7 @@ func TestExitAccountsCli_OK_AllPublicKeys(t *testing.T) {
|
||||
cfg := accounts.PerformExitCfg{
|
||||
ValidatorClient: mockValidatorClient,
|
||||
NodeClient: mockNodeClient,
|
||||
Keymanager: keymanager,
|
||||
Keymanager: km,
|
||||
RawPubKeys: rawPubKeys,
|
||||
FormattedPubKeys: formattedPubKeys,
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ func TestImport_Noninteractive(t *testing.T) {
|
||||
},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
keymanager, err := local.NewKeymanager(
|
||||
newKm, err := local.NewKeymanager(
|
||||
cliCtx.Context,
|
||||
&local.SetupConfig{
|
||||
Wallet: w,
|
||||
@@ -54,9 +54,9 @@ func TestImport_Noninteractive(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
// Make sure there are no accounts at the start.
|
||||
accounts, err := keymanager.ValidatingAccountNames()
|
||||
accNames, err := newKm.ValidatingAccountNames()
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, len(accounts), 0)
|
||||
assert.Equal(t, len(accNames), 0)
|
||||
|
||||
// Create 2 keys.
|
||||
createKeystore(t, keysDir)
|
||||
@@ -149,7 +149,7 @@ func TestImport_Noninteractive_RandomName(t *testing.T) {
|
||||
},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
keymanager, err := local.NewKeymanager(
|
||||
newKm, err := local.NewKeymanager(
|
||||
cliCtx.Context,
|
||||
&local.SetupConfig{
|
||||
Wallet: w,
|
||||
@@ -159,9 +159,9 @@ func TestImport_Noninteractive_RandomName(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
// Make sure there are no accounts at the start.
|
||||
accounts, err := keymanager.ValidatingAccountNames()
|
||||
accNames, err := newKm.ValidatingAccountNames()
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, len(accounts), 0)
|
||||
assert.Equal(t, len(accNames), 0)
|
||||
|
||||
// Create 2 keys.
|
||||
createRandomNameKeystore(t, keysDir)
|
||||
@@ -232,7 +232,7 @@ func TestImport_Noninteractive_Filepath(t *testing.T) {
|
||||
},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
keymanager, err := local.NewKeymanager(
|
||||
newKm, err := local.NewKeymanager(
|
||||
cliCtx.Context,
|
||||
&local.SetupConfig{
|
||||
Wallet: w,
|
||||
@@ -242,9 +242,9 @@ func TestImport_Noninteractive_Filepath(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
// Make sure there are no accounts at the start.
|
||||
accounts, err := keymanager.ValidatingAccountNames()
|
||||
accNames, err := newKm.ValidatingAccountNames()
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, len(accounts), 0)
|
||||
assert.Equal(t, len(accNames), 0)
|
||||
|
||||
require.NoError(t, accountsImport(cliCtx))
|
||||
|
||||
|
||||
@@ -158,12 +158,12 @@ func TestLoadConfigFile(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestLoadConfigFile_OverwriteCorrectly(t *testing.T) {
|
||||
file, err := os.CreateTemp("", "")
|
||||
f, err := os.CreateTemp("", "")
|
||||
require.NoError(t, err)
|
||||
// Set current config to minimal config
|
||||
cfg := params.MinimalSpecConfig().Copy()
|
||||
params.FillTestVersions(cfg, 128)
|
||||
_, err = io.Copy(file, bytes.NewBuffer(params.ConfigToYaml(cfg)))
|
||||
_, err = io.Copy(f, bytes.NewBuffer(params.ConfigToYaml(cfg)))
|
||||
require.NoError(t, err)
|
||||
|
||||
// set active config to mainnet, so that we can confirm LoadChainConfigFile overrides it
|
||||
@@ -177,7 +177,7 @@ func TestLoadConfigFile_OverwriteCorrectly(t *testing.T) {
|
||||
}()
|
||||
|
||||
// load empty config file, so that it defaults to mainnet values
|
||||
require.NoError(t, params.LoadChainConfigFile(file.Name(), nil))
|
||||
require.NoError(t, params.LoadChainConfigFile(f.Name(), nil))
|
||||
if params.BeaconConfig().MinGenesisTime != cfg.MinGenesisTime {
|
||||
t.Errorf("Expected MinGenesisTime to be set to value written to config: %d found: %d",
|
||||
cfg.MinGenesisTime,
|
||||
@@ -276,9 +276,9 @@ func TestConfigParityYaml(t *testing.T) {
|
||||
// configFilePath sets the proper config and returns the relevant
|
||||
// config file path from eth2-spec-tests directory.
|
||||
func configFilePath(t *testing.T, config string) string {
|
||||
filepath, err := bazel.Runfile("external/consensus_spec")
|
||||
fPath, err := bazel.Runfile("external/consensus_spec")
|
||||
require.NoError(t, err)
|
||||
configFilePath := path.Join(filepath, "configs", config+".yaml")
|
||||
configFilePath := path.Join(fPath, "configs", config+".yaml")
|
||||
return configFilePath
|
||||
}
|
||||
|
||||
@@ -286,11 +286,11 @@ func configFilePath(t *testing.T, config string) string {
|
||||
// directory. This method returns a preset file path for each hard fork or
|
||||
// major network upgrade, in order.
|
||||
func presetsFilePath(t *testing.T, config string) []string {
|
||||
filepath, err := bazel.Runfile("external/consensus_spec")
|
||||
fPath, err := bazel.Runfile("external/consensus_spec")
|
||||
require.NoError(t, err)
|
||||
return []string{
|
||||
path.Join(filepath, "presets", config, "phase0.yaml"),
|
||||
path.Join(filepath, "presets", config, "altair.yaml"),
|
||||
path.Join(fPath, "presets", config, "phase0.yaml"),
|
||||
path.Join(fPath, "presets", config, "altair.yaml"),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,9 +13,9 @@ import (
|
||||
)
|
||||
|
||||
func testnetConfigFilePath(t *testing.T, network string) string {
|
||||
filepath, err := bazel.Runfile("external/eth2_networks")
|
||||
fPath, err := bazel.Runfile("external/eth2_networks")
|
||||
require.NoError(t, err)
|
||||
configFilePath := path.Join(filepath, "shared", network, "config.yaml")
|
||||
configFilePath := path.Join(fPath, "shared", network, "config.yaml")
|
||||
return configFilePath
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ package validator_service_config
|
||||
|
||||
import (
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
field_params "github.com/prysmaticlabs/prysm/config/fieldparams"
|
||||
fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams"
|
||||
"github.com/prysmaticlabs/prysm/config/params"
|
||||
)
|
||||
|
||||
@@ -25,7 +25,7 @@ type ProposerOptionPayload struct {
|
||||
// ProposerSettings is a Prysm internal representation of the fee recipient config on the validator client.
|
||||
// ProposerSettingsPayload maps to ProposerSettings on import through the CLI.
|
||||
type ProposerSettings struct {
|
||||
ProposeConfig map[[field_params.BLSPubkeyLength]byte]*ProposerOption
|
||||
ProposeConfig map[[fieldparams.BLSPubkeyLength]byte]*ProposerOption
|
||||
DefaultConfig *ProposerOption
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ package bellatrix
|
||||
import (
|
||||
"bytes"
|
||||
|
||||
field_params "github.com/prysmaticlabs/prysm/config/fieldparams"
|
||||
fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams"
|
||||
"github.com/prysmaticlabs/prysm/encoding/bytesutil"
|
||||
"github.com/prysmaticlabs/prysm/encoding/ssz"
|
||||
enginev1 "github.com/prysmaticlabs/prysm/proto/engine/v1"
|
||||
@@ -38,28 +38,28 @@ func IsEmptyPayload(p *enginev1.ExecutionPayload) bool {
|
||||
if p == nil {
|
||||
return true
|
||||
}
|
||||
if !bytes.Equal(p.ParentHash, make([]byte, field_params.RootLength)) {
|
||||
if !bytes.Equal(p.ParentHash, make([]byte, fieldparams.RootLength)) {
|
||||
return false
|
||||
}
|
||||
if !bytes.Equal(p.FeeRecipient, make([]byte, field_params.FeeRecipientLength)) {
|
||||
if !bytes.Equal(p.FeeRecipient, make([]byte, fieldparams.FeeRecipientLength)) {
|
||||
return false
|
||||
}
|
||||
if !bytes.Equal(p.StateRoot, make([]byte, field_params.RootLength)) {
|
||||
if !bytes.Equal(p.StateRoot, make([]byte, fieldparams.RootLength)) {
|
||||
return false
|
||||
}
|
||||
if !bytes.Equal(p.ReceiptsRoot, make([]byte, field_params.RootLength)) {
|
||||
if !bytes.Equal(p.ReceiptsRoot, make([]byte, fieldparams.RootLength)) {
|
||||
return false
|
||||
}
|
||||
if !bytes.Equal(p.LogsBloom, make([]byte, field_params.LogsBloomLength)) {
|
||||
if !bytes.Equal(p.LogsBloom, make([]byte, fieldparams.LogsBloomLength)) {
|
||||
return false
|
||||
}
|
||||
if !bytes.Equal(p.PrevRandao, make([]byte, field_params.RootLength)) {
|
||||
if !bytes.Equal(p.PrevRandao, make([]byte, fieldparams.RootLength)) {
|
||||
return false
|
||||
}
|
||||
if !bytes.Equal(p.BaseFeePerGas, make([]byte, field_params.RootLength)) {
|
||||
if !bytes.Equal(p.BaseFeePerGas, make([]byte, fieldparams.RootLength)) {
|
||||
return false
|
||||
}
|
||||
if !bytes.Equal(p.BlockHash, make([]byte, field_params.RootLength)) {
|
||||
if !bytes.Equal(p.BlockHash, make([]byte, fieldparams.RootLength)) {
|
||||
return false
|
||||
}
|
||||
if len(p.Transactions) != 0 {
|
||||
@@ -84,31 +84,31 @@ func IsEmptyPayload(p *enginev1.ExecutionPayload) bool {
|
||||
}
|
||||
|
||||
func IsEmptyHeader(h *enginev1.ExecutionPayloadHeader) bool {
|
||||
if !bytes.Equal(h.ParentHash, make([]byte, field_params.RootLength)) {
|
||||
if !bytes.Equal(h.ParentHash, make([]byte, fieldparams.RootLength)) {
|
||||
return false
|
||||
}
|
||||
if !bytes.Equal(h.FeeRecipient, make([]byte, field_params.FeeRecipientLength)) {
|
||||
if !bytes.Equal(h.FeeRecipient, make([]byte, fieldparams.FeeRecipientLength)) {
|
||||
return false
|
||||
}
|
||||
if !bytes.Equal(h.StateRoot, make([]byte, field_params.RootLength)) {
|
||||
if !bytes.Equal(h.StateRoot, make([]byte, fieldparams.RootLength)) {
|
||||
return false
|
||||
}
|
||||
if !bytes.Equal(h.ReceiptsRoot, make([]byte, field_params.RootLength)) {
|
||||
if !bytes.Equal(h.ReceiptsRoot, make([]byte, fieldparams.RootLength)) {
|
||||
return false
|
||||
}
|
||||
if !bytes.Equal(h.LogsBloom, make([]byte, field_params.LogsBloomLength)) {
|
||||
if !bytes.Equal(h.LogsBloom, make([]byte, fieldparams.LogsBloomLength)) {
|
||||
return false
|
||||
}
|
||||
if !bytes.Equal(h.PrevRandao, make([]byte, field_params.RootLength)) {
|
||||
if !bytes.Equal(h.PrevRandao, make([]byte, fieldparams.RootLength)) {
|
||||
return false
|
||||
}
|
||||
if !bytes.Equal(h.BaseFeePerGas, make([]byte, field_params.RootLength)) {
|
||||
if !bytes.Equal(h.BaseFeePerGas, make([]byte, fieldparams.RootLength)) {
|
||||
return false
|
||||
}
|
||||
if !bytes.Equal(h.BlockHash, make([]byte, field_params.RootLength)) {
|
||||
if !bytes.Equal(h.BlockHash, make([]byte, fieldparams.RootLength)) {
|
||||
return false
|
||||
}
|
||||
if !bytes.Equal(h.TransactionsRoot, make([]byte, field_params.RootLength)) {
|
||||
if !bytes.Equal(h.TransactionsRoot, make([]byte, fieldparams.RootLength)) {
|
||||
return false
|
||||
}
|
||||
if len(h.ExtraData) != 0 {
|
||||
|
||||
@@ -14,32 +14,32 @@ var _ fssz.Unmarshaler = (*Domain)(nil)
|
||||
type Domain []byte
|
||||
|
||||
// HashTreeRoot --
|
||||
func (e Domain) HashTreeRoot() ([32]byte, error) {
|
||||
return fssz.HashWithDefaultHasher(e)
|
||||
func (d Domain) HashTreeRoot() ([32]byte, error) {
|
||||
return fssz.HashWithDefaultHasher(d)
|
||||
}
|
||||
|
||||
// HashTreeRootWith --
|
||||
func (e Domain) HashTreeRootWith(hh *fssz.Hasher) error {
|
||||
hh.PutBytes(e[:])
|
||||
func (d Domain) HashTreeRootWith(hh *fssz.Hasher) error {
|
||||
hh.PutBytes(d[:])
|
||||
return nil
|
||||
}
|
||||
|
||||
// UnmarshalSSZ --
|
||||
func (e *Domain) UnmarshalSSZ(buf []byte) error {
|
||||
if len(buf) != e.SizeSSZ() {
|
||||
return fmt.Errorf("expected buffer of length %d received %d", e.SizeSSZ(), len(buf))
|
||||
func (d *Domain) UnmarshalSSZ(buf []byte) error {
|
||||
if len(buf) != d.SizeSSZ() {
|
||||
return fmt.Errorf("expected buffer of length %d received %d", d.SizeSSZ(), len(buf))
|
||||
}
|
||||
|
||||
var b [32]byte
|
||||
item := Domain(b[:])
|
||||
copy(item, buf)
|
||||
*e = item
|
||||
*d = item
|
||||
return nil
|
||||
}
|
||||
|
||||
// MarshalSSZTo --
|
||||
func (e *Domain) MarshalSSZTo(dst []byte) ([]byte, error) {
|
||||
marshalled, err := e.MarshalSSZ()
|
||||
func (d *Domain) MarshalSSZTo(dst []byte) ([]byte, error) {
|
||||
marshalled, err := d.MarshalSSZ()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -47,11 +47,11 @@ func (e *Domain) MarshalSSZTo(dst []byte) ([]byte, error) {
|
||||
}
|
||||
|
||||
// MarshalSSZ --
|
||||
func (e *Domain) MarshalSSZ() ([]byte, error) {
|
||||
return *e, nil
|
||||
func (d *Domain) MarshalSSZ() ([]byte, error) {
|
||||
return *d, nil
|
||||
}
|
||||
|
||||
// SizeSSZ --
|
||||
func (e *Domain) SizeSSZ() int {
|
||||
func (_ *Domain) SizeSSZ() int {
|
||||
return 32
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
fmt "fmt"
|
||||
"fmt"
|
||||
|
||||
fssz "github.com/ferranbt/fastssz"
|
||||
"github.com/prysmaticlabs/prysm/math"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
fmt "fmt"
|
||||
"fmt"
|
||||
|
||||
fssz "github.com/ferranbt/fastssz"
|
||||
)
|
||||
|
||||
@@ -135,14 +135,14 @@ func TestMerkleTrie_MerkleProofOutOfRange(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestMerkleTrieRoot_EmptyTrie(t *testing.T) {
|
||||
trie, err := trie.NewTrie(params.BeaconConfig().DepositContractTreeDepth)
|
||||
newTrie, err := trie.NewTrie(params.BeaconConfig().DepositContractTreeDepth)
|
||||
require.NoError(t, err)
|
||||
testAccount, err := contracts.Setup()
|
||||
require.NoError(t, err)
|
||||
|
||||
depRoot, err := testAccount.Contract.GetDepositRoot(&bind.CallOpts{})
|
||||
require.NoError(t, err)
|
||||
root, err := trie.HashTreeRoot()
|
||||
root, err := newTrie.HashTreeRoot()
|
||||
require.NoError(t, err)
|
||||
require.DeepEqual(t, depRoot, root)
|
||||
}
|
||||
|
||||
@@ -31,11 +31,11 @@ import (
|
||||
)
|
||||
|
||||
func TestPathExpansion(t *testing.T) {
|
||||
user, err := user.Current()
|
||||
u, err := user.Current()
|
||||
require.NoError(t, err)
|
||||
tests := map[string]string{
|
||||
"/home/someuser/tmp": "/home/someuser/tmp",
|
||||
"~/tmp": user.HomeDir + "/tmp",
|
||||
"~/tmp": u.HomeDir + "/tmp",
|
||||
"$DDDXXX/a/b": "/tmp/a/b",
|
||||
"/a/b/": "/a/b",
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/async"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/signing"
|
||||
coreState "github.com/prysmaticlabs/prysm/beacon-chain/core/transition"
|
||||
state_native "github.com/prysmaticlabs/prysm/beacon-chain/state/state-native"
|
||||
statenative "github.com/prysmaticlabs/prysm/beacon-chain/state/state-native"
|
||||
v1 "github.com/prysmaticlabs/prysm/beacon-chain/state/v1"
|
||||
"github.com/prysmaticlabs/prysm/config/features"
|
||||
"github.com/prysmaticlabs/prysm/config/params"
|
||||
@@ -46,15 +46,15 @@ func GenerateGenesisState(ctx context.Context, genesisTime, numValidators uint64
|
||||
func GenerateGenesisStateFromDepositData(
|
||||
ctx context.Context, genesisTime uint64, depositData []*ethpb.Deposit_Data, depositDataRoots [][]byte,
|
||||
) (*ethpb.BeaconState, []*ethpb.Deposit, error) {
|
||||
trie, err := trie.GenerateTrieFromItems(depositDataRoots, params.BeaconConfig().DepositContractTreeDepth)
|
||||
t, err := trie.GenerateTrieFromItems(depositDataRoots, params.BeaconConfig().DepositContractTreeDepth)
|
||||
if err != nil {
|
||||
return nil, nil, errors.Wrap(err, "could not generate Merkle trie for deposit proofs")
|
||||
}
|
||||
deposits, err := GenerateDepositsFromData(depositData, trie)
|
||||
deposits, err := GenerateDepositsFromData(depositData, t)
|
||||
if err != nil {
|
||||
return nil, nil, errors.Wrap(err, "could not generate deposits from the deposit data provided")
|
||||
}
|
||||
root, err := trie.HashTreeRoot()
|
||||
root, err := t.HashTreeRoot()
|
||||
if err != nil {
|
||||
return nil, nil, errors.Wrap(err, "could not hash tree root of deposit trie")
|
||||
}
|
||||
@@ -72,7 +72,7 @@ func GenerateGenesisStateFromDepositData(
|
||||
|
||||
var pbState *ethpb.BeaconState
|
||||
if features.Get().EnableNativeState {
|
||||
pbState, err = state_native.ProtobufBeaconStatePhase0(beaconState.InnerStateUnsafe())
|
||||
pbState, err = statenative.ProtobufBeaconStatePhase0(beaconState.InnerStateUnsafe())
|
||||
} else {
|
||||
pbState, err = v1.ProtobufBeaconState(beaconState.InnerStateUnsafe())
|
||||
}
|
||||
@@ -151,11 +151,11 @@ func depositDataFromKeys(privKeys []bls.SecretKey, pubKeys []bls.PublicKey) ([]*
|
||||
if err != nil {
|
||||
return nil, nil, errors.Wrapf(err, "could not create deposit data for key: %#x", privKeys[i].Marshal())
|
||||
}
|
||||
hash, err := data.HashTreeRoot()
|
||||
h, err := data.HashTreeRoot()
|
||||
if err != nil {
|
||||
return nil, nil, errors.Wrap(err, "could not hash tree root deposit data item")
|
||||
}
|
||||
dataRoots[i] = hash[:]
|
||||
dataRoots[i] = h[:]
|
||||
depositDataItems[i] = data
|
||||
}
|
||||
return depositDataItems, dataRoots, nil
|
||||
|
||||
@@ -52,9 +52,9 @@ func deterministicallyGenerateKeys(startIndex, numKeys uint64) ([]bls.SecretKey,
|
||||
for i := startIndex; i < startIndex+numKeys; i++ {
|
||||
enc := make([]byte, 32)
|
||||
binary.LittleEndian.PutUint32(enc, uint32(i))
|
||||
hash := hash.Hash(enc)
|
||||
h := hash.Hash(enc)
|
||||
// Reverse byte order to big endian for use with big ints.
|
||||
b := bytesutil.ReverseByteOrder(hash[:])
|
||||
b := bytesutil.ReverseByteOrder(h[:])
|
||||
num := new(big.Int)
|
||||
num = num.SetBytes(b)
|
||||
order := new(big.Int)
|
||||
|
||||
@@ -137,7 +137,7 @@ func NewProxy(index int) *Proxy {
|
||||
|
||||
// Start runs a proxy.
|
||||
func (node *Proxy) Start(ctx context.Context) error {
|
||||
file, err := os.Create(path.Join(e2e.TestParams.LogPath, "eth1_proxy_"+strconv.Itoa(node.index)+".log"))
|
||||
f, err := os.Create(path.Join(e2e.TestParams.LogPath, "eth1_proxy_"+strconv.Itoa(node.index)+".log"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -154,14 +154,14 @@ func (node *Proxy) Start(ctx context.Context) error {
|
||||
proxy.WithDestinationAddress(fmt.Sprintf("http://127.0.0.1:%d", e2e.TestParams.Ports.Eth1AuthRPCPort+node.index)),
|
||||
proxy.WithPort(e2e.TestParams.Ports.Eth1ProxyPort + node.index),
|
||||
proxy.WithLogger(log.New()),
|
||||
proxy.WithLogFile(file),
|
||||
proxy.WithLogFile(f),
|
||||
proxy.WithJwtSecret(string(secret)),
|
||||
}
|
||||
nProxy, err := proxy.New(opts...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
log.Infof("Starting eth1 proxy %d with port: %d and file %s", node.index, e2e.TestParams.Ports.Eth1ProxyPort+node.index, file.Name())
|
||||
log.Infof("Starting eth1 proxy %d with port: %d and file %s", node.index, e2e.TestParams.Ports.Eth1ProxyPort+node.index, f.Name())
|
||||
|
||||
// Set cancel into context.
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
|
||||
@@ -255,7 +255,7 @@ func NewKeystoreGenerator() *KeystoreGenerator {
|
||||
return &KeystoreGenerator{started: make(chan struct{})}
|
||||
}
|
||||
|
||||
func (k *KeystoreGenerator) Start(ctx context.Context) error {
|
||||
func (k *KeystoreGenerator) Start(_ context.Context) error {
|
||||
validatorNum := int(params.BeaconConfig().MinGenesisActiveValidatorCount)
|
||||
lighthouseBeaconNum := e2e.TestParams.LighthouseBeaconNodeCount
|
||||
prysmBeaconNum := e2e.TestParams.BeaconNodeCount
|
||||
|
||||
@@ -11,12 +11,6 @@ import (
|
||||
|
||||
type E2EConfigOpt func(*E2EConfig)
|
||||
|
||||
func WithExtraEpochs(extra uint64) E2EConfigOpt {
|
||||
return func(cfg *E2EConfig) {
|
||||
cfg.ExtraEpochs = extra
|
||||
}
|
||||
}
|
||||
|
||||
func WithEpochs(e uint64) E2EConfigOpt {
|
||||
return func(cfg *E2EConfig) {
|
||||
cfg.EpochsToRun = e
|
||||
|
||||
@@ -260,9 +260,6 @@ func TestProxy_CustomInterceptors(t *testing.T) {
|
||||
}
|
||||
|
||||
func Test_isEngineAPICall(t *testing.T) {
|
||||
type args struct {
|
||||
reqBytes []byte
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args *jsonRPCObject
|
||||
|
||||
@@ -23,8 +23,8 @@ func RunEffectiveBalanceUpdatesTests(t *testing.T, config string) {
|
||||
}
|
||||
}
|
||||
|
||||
func processEffectiveBalanceUpdatesWrapper(t *testing.T, state state.BeaconState) (state.BeaconState, error) {
|
||||
state, err := epoch.ProcessEffectiveBalanceUpdates(state)
|
||||
func processEffectiveBalanceUpdatesWrapper(t *testing.T, st state.BeaconState) (state.BeaconState, error) {
|
||||
st, err := epoch.ProcessEffectiveBalanceUpdates(st)
|
||||
require.NoError(t, err, "Could not process final updates")
|
||||
return state, nil
|
||||
return st, nil
|
||||
}
|
||||
|
||||
@@ -23,8 +23,8 @@ func RunEth1DataResetTests(t *testing.T, config string) {
|
||||
}
|
||||
}
|
||||
|
||||
func processEth1DataResetWrapper(t *testing.T, state state.BeaconState) (state.BeaconState, error) {
|
||||
state, err := epoch.ProcessEth1DataReset(state)
|
||||
func processEth1DataResetWrapper(t *testing.T, st state.BeaconState) (state.BeaconState, error) {
|
||||
st, err := epoch.ProcessEth1DataReset(st)
|
||||
require.NoError(t, err, "Could not process final updates")
|
||||
return state, nil
|
||||
return st, nil
|
||||
}
|
||||
|
||||
@@ -23,8 +23,8 @@ func RunHistoricalRootsUpdateTests(t *testing.T, config string) {
|
||||
}
|
||||
}
|
||||
|
||||
func processHistoricalRootsUpdateWrapper(t *testing.T, state state.BeaconState) (state.BeaconState, error) {
|
||||
state, err := epoch.ProcessHistoricalRootsUpdate(state)
|
||||
func processHistoricalRootsUpdateWrapper(t *testing.T, st state.BeaconState) (state.BeaconState, error) {
|
||||
st, err := epoch.ProcessHistoricalRootsUpdate(st)
|
||||
require.NoError(t, err, "Could not process final updates")
|
||||
return state, nil
|
||||
return st, nil
|
||||
}
|
||||
|
||||
@@ -23,8 +23,8 @@ func RunParticipationFlagUpdatesTests(t *testing.T, config string) {
|
||||
}
|
||||
}
|
||||
|
||||
func processParticipationFlagUpdatesWrapper(t *testing.T, state state.BeaconState) (state.BeaconState, error) {
|
||||
state, err := altair.ProcessParticipationFlagUpdates(state)
|
||||
func processParticipationFlagUpdatesWrapper(t *testing.T, st state.BeaconState) (state.BeaconState, error) {
|
||||
st, err := altair.ProcessParticipationFlagUpdates(st)
|
||||
require.NoError(t, err, "Could not process participation flag update")
|
||||
return state, nil
|
||||
return st, nil
|
||||
}
|
||||
|
||||
@@ -23,8 +23,8 @@ func RunRandaoMixesResetTests(t *testing.T, config string) {
|
||||
}
|
||||
}
|
||||
|
||||
func processRandaoMixesResetWrapper(t *testing.T, state state.BeaconState) (state.BeaconState, error) {
|
||||
state, err := epoch.ProcessRandaoMixesReset(state)
|
||||
func processRandaoMixesResetWrapper(t *testing.T, st state.BeaconState) (state.BeaconState, error) {
|
||||
st, err := epoch.ProcessRandaoMixesReset(st)
|
||||
require.NoError(t, err, "Could not process final updates")
|
||||
return state, nil
|
||||
return st, nil
|
||||
}
|
||||
|
||||
@@ -26,8 +26,8 @@ func RunSlashingsTests(t *testing.T, config string) {
|
||||
}
|
||||
}
|
||||
|
||||
func processSlashingsWrapper(t *testing.T, state state.BeaconState) (state.BeaconState, error) {
|
||||
state, err := epoch.ProcessSlashings(state, params.BeaconConfig().ProportionalSlashingMultiplierAltair)
|
||||
func processSlashingsWrapper(t *testing.T, st state.BeaconState) (state.BeaconState, error) {
|
||||
st, err := epoch.ProcessSlashings(st, params.BeaconConfig().ProportionalSlashingMultiplierAltair)
|
||||
require.NoError(t, err, "Could not process slashings")
|
||||
return state, nil
|
||||
return st, nil
|
||||
}
|
||||
|
||||
@@ -23,8 +23,8 @@ func RunSlashingsResetTests(t *testing.T, config string) {
|
||||
}
|
||||
}
|
||||
|
||||
func processSlashingsResetWrapper(t *testing.T, state state.BeaconState) (state.BeaconState, error) {
|
||||
state, err := epoch.ProcessSlashingsReset(state)
|
||||
func processSlashingsResetWrapper(t *testing.T, st state.BeaconState) (state.BeaconState, error) {
|
||||
st, err := epoch.ProcessSlashingsReset(st)
|
||||
require.NoError(t, err, "Could not process final updates")
|
||||
return state, nil
|
||||
return st, nil
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user