Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Experiment Prysm with eip4844 #1

Closed
wants to merge 88 commits into from
Closed
Show file tree
Hide file tree
Changes from 60 commits
Commits
Show all changes
88 commits
Select commit Hold shift + click to select a range
e504d31
Add prepare execution payload
terencechain Mar 4, 2022
ea9979f
Add prepare execution payload
terencechain Mar 4, 2022
e70492e
Add prepare execution payload
terencechain Mar 4, 2022
a8bc8af
Merge branch 'get-payload' of github.com:prysmaticlabs/prysm into get…
terencechain Mar 4, 2022
e3438cd
Update client.go
terencechain Mar 4, 2022
bcffe3d
Update proposer_execution_payload.go
terencechain Mar 4, 2022
9652801
Merge refs/heads/develop into get-payload
prylabs-bulldozer[bot] Mar 4, 2022
7d2a257
Update proposer_execution_payload_test.go
terencechain Mar 4, 2022
aad947b
Merge branch 'get-payload' of github.com:prysmaticlabs/prysm into get…
terencechain Mar 4, 2022
d7489f9
Merge refs/heads/develop into get-payload
prylabs-bulldozer[bot] Mar 6, 2022
80546f8
Initial EIP4844 support
terencechain Mar 7, 2022
658725a
Port eip4844 changes from Prysm
terencechain May 22, 2022
c5ee1c2
Merge branch 'develop' of https://github.com/prysmaticlabs/prysm into…
terencechain May 25, 2022
7fc3a69
Add verify kzgs against version hashes
terencechain May 25, 2022
f566d50
Merge commit '80546f83e9e15e54668e69308f9c5898db667cf1' into inphi/cl…
Inphi Jun 7, 2022
0f8c443
wip: Getting closer to full blobs impl tip
Inphi Jun 9, 2022
e3f1a2d
Add eip4844 fork configs
Inphi Jun 9, 2022
13becad
Blobs verification and signing for block proposals
Inphi Jun 9, 2022
024ad7b
Fix bazel build
Inphi Jun 9, 2022
8e370da
Add blob kzgs to the proposed BeaconBlock
Inphi Jun 9, 2022
533a6b3
fix EIP4844 BeaconBlock signature
Inphi Jun 9, 2022
4381444
Update geth dependency
Inphi Jun 9, 2022
d3b6b2d
Fix blobsBundle JSON parsing
Inphi Jun 10, 2022
bf1b5a5
[EIP-4844] Fix BlobVersionedHashes SSZ parsing (#1)
mdehoog Jun 13, 2022
b3d2ed1
TxPeekBlobVersionedHashes: fix hash copying (#3)
mdehoog Jun 13, 2022
eb1c7bd
Replace [32]byte with common.Hash (#4)
mdehoog Jun 13, 2022
27677da
assert len(blobkzgs) == len(blob_versioned_hashes)
Inphi Jun 13, 2022
3a6a7d7
persist proposed blobs sidecar
Inphi Jun 13, 2022
b6a05ec
add missing bazel dependencies
Inphi Jun 13, 2022
40c754e
p2p: Implement BlobsSidecarsByRange RPC
Inphi Jun 14, 2022
cb3da77
testing: Assert received fields for BlobsSidecarsByRange RPC
Inphi Jun 14, 2022
31e1999
add generated ssz files for BlobsSidecarsByRangeRequest
Inphi Jun 14, 2022
e2bf25e
fix BlobsSidecarsByRange RPC Request routine
Inphi Jun 14, 2022
53bb657
EIP-4844 beacon RPCs (#5)
mdehoog Jun 14, 2022
d5d1b33
Add rpc_blobs_sidecars_by_range_test to bazel deps
Inphi Jun 14, 2022
be8c029
validate BeaconBlock for EIP-4844
Inphi Jun 15, 2022
901a087
fix SaveBlobs span typo
Inphi Jun 15, 2022
ff822a6
Avoid EIP-4844 validation for older block versions
Inphi Jun 16, 2022
027e49c
add IsPreEIP4844Version utility func
Inphi Jun 16, 2022
ac4a4cc
Fix BlobsBundle JSON (un)marshaling (#6)
mdehoog Jun 16, 2022
2e0a6d6
p2p: Handle sidecar message broadcasts (#7)
Inphi Jun 16, 2022
cb524c5
Merge remote-tracking branch 'origin/develop' into inphi/clean-slate-…
Inphi Jun 24, 2022
b2a9a79
Sync: Blobs Sidecar (#8)
Inphi Jun 30, 2022
7d6f079
testing: validateBeaconBlock w/ kzgs
Inphi Jun 30, 2022
b2b4aa9
Prune blobs older than MIN_EPOCHS_FOR_BLOBS_SIDECARS_REQUESTS
Inphi Jul 5, 2022
ebe1e9e
nit
Inphi Jul 5, 2022
b18ebab
Incorporate data availability to fork-choice
Inphi Jul 8, 2022
eed1e47
Add --eip4844 testnet flag for ez config
Inphi Jul 13, 2022
48c26b9
configure blobs prune period in testnet
Inphi Jul 13, 2022
41f34aa
tweak eip4844 testnet configs
Inphi Jul 13, 2022
bd01ffa
Add aggregated proof to APIs (#10)
mdehoog Jul 21, 2022
920e075
Update bazel deps; errcheck linting
Inphi Jul 22, 2022
5b53ad6
Add EIP-4844 bootstrap node for devnet
Inphi Jul 27, 2022
bc0ba2d
Rate-limit sidecar requests during initial-sync
Inphi Jul 28, 2022
109a0f5
update EIP4844 BeaconChainConfig
Inphi Jul 28, 2022
d8187b7
Merge branch 'develop' of https://github.com/prysmaticlabs/prysm into…
terencechain Jul 31, 2022
bff4435
Merge branch 'inphi/clean-slate' of https://github.com/inphi/prysm in…
terencechain Jul 31, 2022
bd6cf8d
Sync with @inphi's clean-slate and upstream
terencechain Aug 1, 2022
9b260be
Sync with upstream
terencechain Aug 1, 2022
a390c74
Encapsulate sidecar within signed block interface
terencechain Aug 1, 2022
37118e7
Clean up core
terencechain Aug 2, 2022
080810e
Merge branch 'develop' of https://github.com/prysmaticlabs/prysm into…
terencechain Aug 4, 2022
f04b2be
Sync with native block changes
terencechain Aug 4, 2022
e71124e
Clean up db and generated pbs
terencechain Aug 4, 2022
1391cce
Refactor forkchoice valid data status
terencechain Aug 6, 2022
1d800e4
Merge branch 'develop' of https://github.com/prysmaticlabs/prysm into…
terencechain Aug 10, 2022
00c57e7
Sync with upstream
terencechain Aug 10, 2022
a22d62e
Sync with upstream
terencechain Aug 20, 2022
5c2ebec
Can build
terencechain Aug 20, 2022
f871d76
Merge branch 'develop' of github.com:terencechain/prysm into eip4844
terencechain Sep 23, 2022
a032cf2
Sync with upstream
terencechain Sep 23, 2022
1e5c077
Add `compute_aggregated_poly_and_commitment`
terencechain Sep 27, 2022
404e1a1
Merge branch 'develop' into eip4844
terencechain Oct 24, 2022
608f404
Sync with upstream
terencechain Oct 24, 2022
3400af6
rotating buffer db schema for blobs
rauljordan Oct 25, 2022
52a87e9
unit test
rauljordan Oct 25, 2022
752bb63
save blobs test
rauljordan Oct 25, 2022
8a7ab75
algorithm and test done
rauljordan Oct 25, 2022
31f369c
comment
rauljordan Oct 25, 2022
9096c4a
dedup comment
rauljordan Oct 25, 2022
3d45b83
Update beacon-chain/db/kv/blobs.go
rauljordan Oct 25, 2022
826a930
Update beacon-chain/db/kv/blobs.go
rauljordan Oct 25, 2022
8024758
Update beacon-chain/db/kv/blobs.go
rauljordan Oct 25, 2022
5410c30
Merge branch 'blob-rotating-buffer' of github.com:rauljordan/prysm in…
rauljordan Oct 25, 2022
8b8a380
radek feedback
rauljordan Oct 25, 2022
a1e5cc3
more feedback resolved
rauljordan Oct 25, 2022
64d9fc6
Merge branch 'eip4844' into blob-rotating-buffer
terencechain Nov 4, 2022
aba7e73
Merge pull request #3 from rauljordan/blob-rotating-buffer
terencechain Nov 4, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions beacon-chain/blockchain/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ go_library(
"//beacon-chain/cache:go_default_library",
"//beacon-chain/cache/depositcache:go_default_library",
"//beacon-chain/core/altair:go_default_library",
"//beacon-chain/core/blob:go_default_library",
"//beacon-chain/core/blocks:go_default_library",
"//beacon-chain/core/epoch/precompute:go_default_library",
"//beacon-chain/core/feed:go_default_library",
Expand Down
11 changes: 9 additions & 2 deletions beacon-chain/blockchain/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ func logStateTransitionData(b interfaces.BeaconBlock) error {
if len(b.Body().VoluntaryExits()) > 0 {
log = log.WithField("voluntaryExits", len(b.Body().VoluntaryExits()))
}
if b.Version() == version.Altair || b.Version() == version.Bellatrix {
if b.Version() == version.Altair || b.Version() == version.Bellatrix || b.Version() == version.EIP4844 {
agg, err := b.Body().SyncAggregate()
if err != nil {
return err
}
log = log.WithField("syncBitsCount", agg.SyncCommitteeBits.Count())
}
if b.Version() == version.Bellatrix {
if b.Version() == version.Bellatrix || b.Version() == version.EIP4844 {
p, err := b.Body().Execution()
if err != nil {
return err
Expand All @@ -56,6 +56,13 @@ func logStateTransitionData(b interfaces.BeaconBlock) error {
}
log = log.WithField("txCount", len(txs))
}
if b.Version() == version.EIP4844 {
k, err := b.Body().BlobKzgs()
if err != nil {
return err
}
log = log.WithField("blobKzgCount", len(k))
}
log.Info("Finished applying state transition")
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion beacon-chain/blockchain/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ func reportEpochMetrics(ctx context.Context, postState, headState state.BeaconSt
if err != nil {
return err
}
case version.Altair, version.Bellatrix:
case version.Altair, version.Bellatrix, version.EIP4844:
v, b, err = altair.InitializePrecomputeValidators(ctx, headState)
if err != nil {
return err
Expand Down
30 changes: 28 additions & 2 deletions beacon-chain/blockchain/process_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/async/event"
"github.com/prysmaticlabs/prysm/beacon-chain/core/blob"
"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"
Expand Down Expand Up @@ -280,8 +281,7 @@ func getStateVersionAndPayload(st state.BeaconState) (int, *enginev1.ExecutionPa
return preStateVersion, preStateHeader, nil
}

func (s *Service) onBlockBatch(ctx context.Context, blks []interfaces.SignedBeaconBlock,
blockRoots [][32]byte) error {
func (s *Service) onBlockBatch(ctx context.Context, blks []interfaces.SignedBeaconBlock, blockRoots [][32]byte) error {
ctx, span := trace.StartSpan(ctx, "blockChain.onBlockBatch")
defer span.End()

Expand Down Expand Up @@ -400,6 +400,11 @@ func (s *Service) onBlockBatch(ctx context.Context, blks []interfaces.SignedBeac
tracing.AnnotateError(span, err)
return err
}

if err := s.saveSidecar(ctx, b); err != nil {
return err
}

if i > 0 && jCheckpoints[i].Epoch > jCheckpoints[i-1].Epoch {
if err := s.cfg.BeaconDB.SaveJustifiedCheckpoint(ctx, jCheckpoints[i]); err != nil {
tracing.AnnotateError(span, err)
Expand Down Expand Up @@ -543,15 +548,36 @@ func (s *Service) InsertSlashingsToForkChoiceStore(ctx context.Context, slashing
func (s *Service) savePostStateInfo(ctx context.Context, r [32]byte, b interfaces.SignedBeaconBlock, st state.BeaconState) error {
ctx, span := trace.StartSpan(ctx, "blockChain.savePostStateInfo")
defer span.End()

if err := s.cfg.BeaconDB.SaveBlock(ctx, b); err != nil {
return errors.Wrapf(err, "could not save block from slot %d", b.Block().Slot())
}
if err := s.saveSidecar(ctx, b); err != nil {
return errors.Wrapf(err, "could not save sidecar from slot %d", b.Block().Slot())
}
if err := s.cfg.StateGen.SaveState(ctx, r, st); err != nil {
return errors.Wrap(err, "could not save state")
}
return nil
}

// Saves sidecar to the DB for the compatible block that contains the sidecar.
func (s *Service) saveSidecar(ctx context.Context, b interfaces.SignedBeaconBlock) error {
ok, err := blob.BlockContainsSidecar(b)
if err != nil {
return errors.Wrap(err, "could not determine if block contains sidecar")
}
if !ok {
return nil
}

sc, err := b.SideCar()
if err != nil {
return errors.Wrap(err, "could not get sidecar")
}
return s.cfg.BeaconDB.SaveBlobsSidecar(ctx, sc.Message)
}

// This removes the attestations from the mem pool. It will only remove the attestations if input root `r` is canonical,
// meaning the block `b` is part of the canonical chain.
func (s *Service) pruneCanonicalAttsFromPool(ctx context.Context, r [32]byte, b interfaces.SignedBeaconBlock) error {
Expand Down
41 changes: 39 additions & 2 deletions beacon-chain/blockchain/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/prysmaticlabs/prysm/async/event"
"github.com/prysmaticlabs/prysm/beacon-chain/cache"
"github.com/prysmaticlabs/prysm/beacon-chain/cache/depositcache"
"github.com/prysmaticlabs/prysm/beacon-chain/core/blob"
"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"
Expand Down Expand Up @@ -205,9 +206,9 @@ func (s *Service) StartFromSavedState(saved state.BeaconState) error {
var forkChoicer f.ForkChoicer
fRoot := s.ensureRootNotZeros(bytesutil.ToBytes32(finalized.Root))
if features.Get().EnableForkChoiceDoublyLinkedTree {
forkChoicer = doublylinkedtree.New()
forkChoicer = doublylinkedtree.New(NewDBDataAvailability(s.cfg.BeaconDB))
} else {
forkChoicer = protoarray.New()
forkChoicer = protoarray.New(NewDBDataAvailability(s.cfg.BeaconDB))
}
s.cfg.ForkChoiceStore = forkChoicer
if err := forkChoicer.UpdateJustifiedCheckpoint(&forkchoicetypes.Checkpoint{Epoch: justified.Epoch,
Expand Down Expand Up @@ -510,3 +511,39 @@ func spawnCountdownIfPreGenesis(ctx context.Context, genesisTime time.Time, db d
}
go slots.CountdownToGenesis(ctx, genesisTime, uint64(gState.NumValidators()), gRoot)
}

type dbDataAvailability struct {
db db.ReadOnlyDatabase
}

func NewDBDataAvailability(db db.ReadOnlyDatabase) f.DataAvailability {
return &dbDataAvailability{db}
}

func (d *dbDataAvailability) IsDataAvailable(ctx context.Context, root [32]byte) error {
b, err := d.db.Block(ctx, root)
if err != nil {
return err
}
if err := wrapper.BeaconBlockIsNil(b); err != nil {
return err
}
if !blob.BlockContainsKZGs(b.Block()) {
// no sidecar referenced. We have all the data we need
return nil
}

kzgs, err := b.Block().Body().BlobKzgs()
if err != nil {
// shouldn't happen if blob contains kzgs
return err
}
sidecar, err := d.db.BlobsSidecar(ctx, root)
if err != nil {
return err
}
if sidecar.BeaconBlockSlot != b.Block().Slot() {
return errors.New("blobs sidecar is unavailable")
}
return blob.VerifyBlobsSidecar(b.Block().Slot(), root, bytesutil.ToBytes48Array(kzgs), sidecar)
}
51 changes: 49 additions & 2 deletions beacon-chain/blockchain/testing/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@ type ChainService struct {
DB db.Database
State state.BeaconState
Block interfaces.SignedBeaconBlock
Sidecar *ethpb.BlobsSidecar
VerifyBlkDescendantErr error
stateNotifier statefeed.Notifier
BlocksReceived []interfaces.SignedBeaconBlock
SidecarsReceived []*ethpb.BlobsSidecar
SyncCommitteeIndices []types.CommitteeIndex
blockNotifier blockfeed.Notifier
opNotifier opfeed.Notifier
Expand Down Expand Up @@ -194,7 +196,7 @@ func (s *ChainService) ReceiveBlockInitialSync(ctx context.Context, block interf
}

// ReceiveBlockBatch processes blocks in batches from initial-sync.
func (s *ChainService) ReceiveBlockBatch(ctx context.Context, blks []interfaces.SignedBeaconBlock, _ [][32]byte) error {
func (s *ChainService) ReceiveBlockBatch(ctx context.Context, blks []interfaces.SignedBeaconBlock, _ [][32]byte, sidecars []*ethpb.BlobsSidecar) error {
if s.State == nil {
return ErrNilState
}
Expand All @@ -210,20 +212,35 @@ func (s *ChainService) ReceiveBlockBatch(ctx context.Context, blks []interfaces.
if err != nil {
return err
}
sidecar := findSidecarForBlock(b.Block(), signingRoot, sidecars)
if sidecar != nil {
if bytesutil.ToBytes32(sidecar.BeaconBlockRoot) != signingRoot {
return errors.Errorf("sidecar root mismatch blk=%#x sidecar=%#x", signingRoot, sidecar.BeaconBlockRoot)
}
if sidecar.BeaconBlockSlot != b.Block().Slot() {
return errors.Errorf("sidecar slot mismatch blk=%#x sidecar=%#x", b.Block().Slot(), sidecar.BeaconBlockSlot)
}
}
if s.DB != nil {
if sidecar != nil {
if err := s.DB.SaveBlobsSidecar(ctx, sidecar); err != nil {
return err
}
}
if err := s.DB.SaveBlock(ctx, b); err != nil {
return err
}
logrus.Infof("Saved block with root: %#x at slot %d", signingRoot, b.Block().Slot())
}
s.Root = signingRoot[:]
s.Block = b
s.Sidecar = sidecar
}
return nil
}

// ReceiveBlock mocks ReceiveBlock method in chain service.
func (s *ChainService) ReceiveBlock(ctx context.Context, block interfaces.SignedBeaconBlock, _ [32]byte) error {
func (s *ChainService) ReceiveBlock(ctx context.Context, block interfaces.SignedBeaconBlock, _ [32]byte, sidecar *ethpb.BlobsSidecar) error {
if s.ReceiveBlockMockErr != nil {
return s.ReceiveBlockMockErr
}
Expand All @@ -241,14 +258,31 @@ func (s *ChainService) ReceiveBlock(ctx context.Context, block interfaces.Signed
if err != nil {
return err
}
if sidecar != nil {
if bytesutil.ToBytes32(sidecar.BeaconBlockRoot) != signingRoot {
return errors.Errorf("sidecar root mismatch blk=%#x sidecar=%#x", signingRoot, sidecar.BeaconBlockRoot)
}
if sidecar.BeaconBlockSlot != block.Block().Slot() {
return errors.Errorf("sidecar slot mismatch blk=%#x sidecar=%#x", block.Block().Slot(), sidecar.BeaconBlockSlot)
}
}
if sidecar != nil {
s.SidecarsReceived = append(s.SidecarsReceived, sidecar)
}
if s.DB != nil {
if sidecar != nil {
if err := s.DB.SaveBlobsSidecar(ctx, sidecar); err != nil {
return err
}
}
if err := s.DB.SaveBlock(ctx, block); err != nil {
return err
}
logrus.Infof("Saved block with root: %#x at slot %d", signingRoot, block.Block().Slot())
}
s.Root = signingRoot[:]
s.Block = block
s.Sidecar = sidecar
return nil
}

Expand Down Expand Up @@ -464,3 +498,16 @@ func (s *ChainService) ReceiveAttesterSlashing(context.Context, *ethpb.AttesterS
func (s *ChainService) IsFinalized(_ context.Context, blockRoot [32]byte) bool {
return s.FinalizedRoots[blockRoot]
}

func findSidecarForBlock(b interfaces.BeaconBlock, blkRoot [32]byte, sidecars []*ethpb.BlobsSidecar) *ethpb.BlobsSidecar {
for _, s := range sidecars {
if b.Slot() != s.BeaconBlockSlot {
continue
}
if blkRoot != bytesutil.ToBytes32(s.BeaconBlockRoot) {
continue
}
return s
}
return nil
}
2 changes: 1 addition & 1 deletion beacon-chain/cache/sync_committee_head_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (c *SyncCommitteeHeadStateCache) Get(slot types.Slot) (state.BeaconState, e
return nil, ErrIncorrectType
}
switch st.Version() {
case version.Altair, version.Bellatrix:
case version.Altair, version.Bellatrix, version.EIP4844:
default:
return nil, ErrIncorrectType
}
Expand Down
4 changes: 2 additions & 2 deletions beacon-chain/core/altair/transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ func ProcessEpoch(ctx context.Context, state state.BeaconState) (state.BeaconSta
}

// Modified in Altair and Bellatrix.
proportionalSlashingMultipler, err := state.ProportionalSlashingMultiplier()
proportionalSlashingMultiplier, err := state.ProportionalSlashingMultiplier()
if err != nil {
return nil, err
}
state, err = e.ProcessSlashings(state, proportionalSlashingMultipler)
state, err = e.ProcessSlashings(state, proportionalSlashingMultiplier)
if err != nil {
return nil, err
}
Expand Down
18 changes: 18 additions & 0 deletions beacon-chain/core/blob/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
load("@prysm//tools/go:def.bzl", "go_library")

go_library(
name = "go_default_library",
srcs = ["sidecar.go"],
importpath = "github.com/prysmaticlabs/prysm/beacon-chain/core/blob",
visibility = ["//visibility:public"],
deps = [
"//beacon-chain/core/blocks:go_default_library",
"//consensus-types/interfaces:go_default_library",
"//consensus-types/primitives:go_default_library",
"//consensus-types/wrapper:go_default_library",
"//encoding/bytesutil:go_default_library",
"//proto/prysm/v1alpha1:go_default_library",
"@com_github_ethereum_go_ethereum//core/types:go_default_library",
"@com_github_pkg_errors//:go_default_library",
],
)
Loading