mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-05 17:22:18 +00:00
8a01d412f5
* starting * Reimplement store * begin on proposer boost * implement fork choice proposer boost algorithm * boosting * gaz * add mutexes and previous root * comment on compute proposer boost * safe * rem todo * reset and add tests * unit test for proposer boost score * boost works * Can process block * Basic test case passing * ex ante * test * propoer test * More progresses * More fixes * rm unused pieces * Refactor, add phase 0 * locks * vanilla ex-ante attack * test similar to spec test * works works works * boost test working for num votes > proposer boost weight * commentary fixes * rem unused * comments * Proposer boost use store time * Reset proposer root * debugging * passing * Rm unused visibility imports * Move update head to better place * Fix deepsrc complains * Fix more complains * Raul's feedback * Use correct byte lengths Co-authored-by: Raul Jordan <raul@prysmaticlabs.com>
59 lines
2.2 KiB
Go
59 lines
2.2 KiB
Go
package forkchoice
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/blockchain"
|
|
mock "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing"
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/cache/depositcache"
|
|
coreTime "github.com/prysmaticlabs/prysm/beacon-chain/core/time"
|
|
testDB "github.com/prysmaticlabs/prysm/beacon-chain/db/testing"
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/forkchoice/protoarray"
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/operations/attestations"
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/state"
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/state/stategen"
|
|
"github.com/prysmaticlabs/prysm/config/params"
|
|
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
|
"github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/block"
|
|
"github.com/prysmaticlabs/prysm/testing/require"
|
|
)
|
|
|
|
func startChainService(t *testing.T, st state.BeaconState, block block.SignedBeaconBlock) *blockchain.Service {
|
|
db := testDB.SetupDB(t)
|
|
ctx := context.Background()
|
|
require.NoError(t, db.SaveBlock(ctx, block))
|
|
r, err := block.Block().HashTreeRoot()
|
|
require.NoError(t, err)
|
|
require.NoError(t, db.SaveGenesisBlockRoot(ctx, r))
|
|
require.NoError(t, db.SaveState(ctx, st, r))
|
|
cp := ðpb.Checkpoint{
|
|
Epoch: coreTime.CurrentEpoch(st),
|
|
Root: r[:],
|
|
}
|
|
require.NoError(t, db.SaveJustifiedCheckpoint(ctx, cp))
|
|
require.NoError(t, db.SaveFinalizedCheckpoint(ctx, cp))
|
|
attPool, err := attestations.NewService(ctx, &attestations.Config{
|
|
Pool: attestations.NewPool(),
|
|
})
|
|
require.NoError(t, err)
|
|
|
|
depositCache, err := depositcache.New()
|
|
require.NoError(t, err)
|
|
|
|
opts := append([]blockchain.Option{},
|
|
blockchain.WithFinalizedStateAtStartUp(st),
|
|
blockchain.WithDatabase(db),
|
|
blockchain.WithAttestationService(attPool),
|
|
blockchain.WithForkChoiceStore(protoarray.New(0, 0, params.BeaconConfig().ZeroHash)),
|
|
blockchain.WithStateGen(stategen.New(db)),
|
|
blockchain.WithStateNotifier(&mock.MockStateNotifier{}),
|
|
blockchain.WithAttestationPool(attestations.NewPool()),
|
|
blockchain.WithDepositCache(depositCache),
|
|
)
|
|
service, err := blockchain.NewService(context.Background(), opts...)
|
|
require.NoError(t, err)
|
|
service.Start()
|
|
return service
|
|
}
|