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

npernas/polymer devnet #30

Draft
wants to merge 3 commits into
base: ds/merge_upstream
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
74 changes: 74 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: docker-prysm

on:
push:
tags:
- "v*.*.*"

env:
REGISTRY_IMAGE_PREFIX: ghcr.io/polymerdao/prysm

jobs:
build:
runs-on: ubuntu-22.04-16core
strategy:
fail-fast: true
matrix:
binary:
- beacon-chain
- prysmctl
- validator
steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: ${{ github.event.inputs.build-ref }}

- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: |
${{ env.REGISTRY_IMAGE_PREFIX }}-${{ matrix.binary }}
tags: |
type=sha
type=semver,pattern={{raw}}
labels: |
org.opencontainers.image.source=https://github.com/polymerdao/prysm
org.opencontainers.image.title=prysm
org.opencontainers.image.url=https://github.com/polymerdao/prysm

- name: Authenticate Docker
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.PACKAGES_TOKEN }}

- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Read bazel version
run: |
echo "BAZEL_VERSION=$( cat .bazelversion )" >> "$GITHUB_ENV"

- name: Build and push
uses: docker/build-push-action@v4
env:
REGISTRY_IMAGE: ${{ env.REGISTRY_IMAGE_PREFIX }}-${{ matrix.binary }}
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
provenance: false
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
BINARY=${{ matrix.binary }}
BAZEL_VERSION=${{ env.BAZEL_VERSION }}
# TODO: these cause the runner to hang and crash
# cache-from: type=registry,ref=${{ env.REGISTRY_IMAGE }}:buildcache
# cache-to: type=registry,ref=${{ env.REGISTRY_IMAGE }}:buildcache,mode=max
38 changes: 38 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# based on tools/cross-toolchain/Dockerfile
FROM --platform=$BUILDPLATFORM debian:bullseye-slim as build-env

ARG TARGETARCH
ARG BUILDARCH
ARG BINARY
ARG BAZEL_VERSION

# install gnu/gcc cross-build toolchain (gcc 8.3)
RUN apt-get update && \
apt-get install -y \
curl xz-utils patch python \
gcc g++ git \
gcc-aarch64-linux-gnu g++-aarch64-linux-gnu

# install llvm/clang cross-build toolchains
ENV INSTALL_LLVM_VERSION=12.0.0
ADD tools/cross-toolchain/install_clang_cross.sh /tmp/install_clang_cross.sh
RUN /tmp/install_clang_cross.sh

WORKDIR /src
COPY ./ .

RUN case "$BUILDARCH" in \
amd64) arch=x86_64 ;; \
arm64) arch=arm64 ;; \
esac && \
curl -sL "https://releases.bazel.build/${BAZEL_VERSION}/release/bazel-${BAZEL_VERSION}-linux-${arch}" -o /tmp/bazel && \
chmod +x /tmp/bazel && \
/tmp/bazel build --config="linux_${TARGETARCH}" "//cmd/$BINARY:$BINARY"

FROM alpine:3.18

ARG BINARY

RUN apk add --no-cache libstdc++ libc6-compat gcompat

COPY --from=build-env "/src/bazel-bin/cmd/$BINARY/${BINARY}_/$BINARY" /usr/bin
1 change: 1 addition & 0 deletions beacon-chain/blockchain/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ type Service struct {
clockSetter startup.ClockSetter
clockWaiter startup.ClockWaiter
syncComplete chan struct{}
processAttestationsLock sync.Mutex
lastPublishedLightClientEpoch primitives.Epoch
}

Expand Down
1 change: 1 addition & 0 deletions beacon-chain/core/epoch/precompute/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ go_library(
"//beacon-chain/core/helpers:go_default_library",
"//beacon-chain/core/time:go_default_library",
"//beacon-chain/state:go_default_library",
"//config/features:go_default_library",
"//config/params:go_default_library",
"//consensus-types/primitives:go_default_library",
"//math:go_default_library",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/prysmaticlabs/prysm/v4/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/v4/beacon-chain/core/time"
"github.com/prysmaticlabs/prysm/v4/beacon-chain/state"
"github.com/prysmaticlabs/prysm/v4/config/features"
"github.com/prysmaticlabs/prysm/v4/config/params"
ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/v4/time/slots"
Expand Down Expand Up @@ -55,6 +56,11 @@ func UnrealizedCheckpoints(st state.BeaconState) (*ethpb.Checkpoint, *ethpb.Chec
// current_target_balance = get_attesting_balance(state, current_attestations)
// weigh_justification_and_finalization(state, total_active_balance, previous_target_balance, current_target_balance)
func ProcessJustificationAndFinalizationPreCompute(state state.BeaconState, pBal *Balance) (state.BeaconState, error) {
if features.Get().PolymerDevnetMode {
newBits := processJustificationBits(state, pBal.ActiveCurrentEpoch, pBal.PrevEpochTargetAttested, pBal.CurrentEpochAttested)
return weighJustificationAndFinalization(state, newBits)
}

canProcessSlot, err := slots.EpochStart(2 /*epoch*/)
if err != nil {
return nil, err
Expand Down
14 changes: 14 additions & 0 deletions beacon-chain/execution/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package execution
import (
"context"
"fmt"
"github.com/prysmaticlabs/prysm/v4/config/features"
"math/big"
"reflect"
"runtime/debug"
Expand Down Expand Up @@ -470,6 +471,12 @@ func (s *Service) handleETH1FollowDistance() {
log.Warn("Execution client is not syncing")
}
if !s.chainStartData.Chainstarted {
if features.Get().PolymerDevnetMode {
if s.latestEth1Data.LastRequestedBlock == params.BeaconNetworkConfig().ContractDeploymentBlock {
return
}
}

if err := s.processChainStartFromBlockNum(ctx, big.NewInt(int64(s.latestEth1Data.LastRequestedBlock))); err != nil {
s.runError = errors.Wrap(err, "processChainStartFromBlockNum")
log.Error(err)
Expand Down Expand Up @@ -620,6 +627,13 @@ func (s *Service) logTillChainStart(ctx context.Context) {
if s.chainStartData.Chainstarted {
return
}

if features.Get().PolymerDevnetMode {
if s.latestEth1Data.LastRequestedBlock == params.BeaconNetworkConfig().ContractDeploymentBlock {
return
}
}

_, blockTime, err := s.retrieveBlockHashAndTime(s.ctx, big.NewInt(int64(s.latestEth1Data.LastRequestedBlock)))
if err != nil {
log.Error(err)
Expand Down
11 changes: 10 additions & 1 deletion beacon-chain/p2p/pubsub_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
pubsubpb "github.com/libp2p/go-libp2p-pubsub/pb"
"github.com/libp2p/go-libp2p/core/peer"
"github.com/prysmaticlabs/prysm/v4/beacon-chain/p2p/encoder"
"github.com/prysmaticlabs/prysm/v4/config/features"
"github.com/prysmaticlabs/prysm/v4/config/params"
"github.com/prysmaticlabs/prysm/v4/network/forks"
)
Expand Down Expand Up @@ -37,7 +38,15 @@ func (s *Service) CanSubscribe(topic string) bool {
if parts[1] != "eth2" {
return false
}
phase0ForkDigest, err := s.currentForkDigest()

var phase0ForkDigest [4]byte
var err error
if features.Get().PolymerDevnetMode {
phase0ForkDigest, err = forks.ForkDigestFromEpoch(params.BeaconConfig().GenesisEpoch, s.genesisValidatorsRoot)
} else {
phase0ForkDigest, err = s.currentForkDigest()
}

if err != nil {
log.WithError(err).Error("Could not determine fork digest")
return false
Expand Down
9 changes: 7 additions & 2 deletions beacon-chain/rpc/prysm/v1alpha1/debug/p2p.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"github.com/golang/protobuf/ptypes/empty"
"github.com/libp2p/go-libp2p/core/network"
"github.com/libp2p/go-libp2p/core/peer"
"github.com/libp2p/go-libp2p/core/protocol"
"github.com/prysmaticlabs/prysm/v4/beacon-chain/p2p"
ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1"
"google.golang.org/grpc/codes"
Expand Down Expand Up @@ -92,8 +91,14 @@ func (ds *Server) getPeer(pid peer.ID) (*ethpb.DebugPeerResponse, error) {
if err != nil || !ok {
aVersion = ""
}

var sProtocols []string
for _, p := range protocols {
sProtocols = append(sProtocols, string(p))
}

peerInfo := &ethpb.DebugPeerResponse_PeerInfo{
Protocols: protocol.ConvertToStrings(protocols),
Protocols: sProtocols,
FaultCount: uint64(resp),
ProtocolVersion: pVersion,
AgentVersion: aVersion,
Expand Down
14 changes: 13 additions & 1 deletion config/features/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ type Flags struct {
SaveFullExecutionPayloads bool // Save full beacon blocks with execution payloads in the database.
EnableStartOptimistic bool // EnableStartOptimistic treats every block as optimistic at startup.

DisableResourceManager bool // Disables running the node with libp2p's resource manager.
DisableResourceManager bool // Disables running the node with libp2p's resource manager.

PolymerDevnetMode bool // A special mode for Polymer devkit

DisableStakinContractCheck bool // Disables check for deposit contract when proposing blocks

EnableVerboseSigVerification bool // EnableVerboseSigVerification specifies whether to verify individual signature if batch verification fails
Expand Down Expand Up @@ -205,6 +208,10 @@ func ConfigureBeaconChain(ctx *cli.Context) error {
logEnabled(SaveFullExecutionPayloads)
cfg.SaveFullExecutionPayloads = true
}
if ctx.Bool(PolymerDevnetMode.Name) {
logEnabled(PolymerDevnetMode)
cfg.PolymerDevnetMode = true
}
if ctx.Bool(enableStartupOptimistic.Name) {
logEnabled(enableStartupOptimistic)
cfg.EnableStartOptimistic = true
Expand Down Expand Up @@ -277,6 +284,11 @@ func ConfigureValidator(ctx *cli.Context) error {
logEnabled(EnableBeaconRESTApi)
cfg.EnableBeaconRESTApi = true
}
if ctx.Bool(PolymerDevnetMode.Name) {
logEnabled(PolymerDevnetMode)
cfg.PolymerDevnetMode = true
}

cfg.KeystoreImportDebounceInterval = ctx.Duration(dynamicKeyReloadDebounceInterval.Name)
Init(cfg)
return nil
Expand Down
6 changes: 6 additions & 0 deletions config/features/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ var (
" (Warning): Once enabled, this feature migrates your database in to a new schema and " +
"there is no going back. At worst, your entire database might get corrupted.",
}
PolymerDevnetMode = &cli.BoolFlag{
Name: "enable-polymer-devnet-mode",
Usage: "This will enable fast devnet chain mode for Polymer devkit",
}
enableStartupOptimistic = &cli.BoolFlag{
Name: "startup-optimistic",
Usage: "Treats every block as optimistically synced at launch. Use with caution",
Expand Down Expand Up @@ -179,6 +183,7 @@ var ValidatorFlags = append(deprecatedFlags, []cli.Flag{
enableSlashingProtectionPruning,
enableDoppelGangerProtection,
EnableBeaconRESTApi,
PolymerDevnetMode,
}...)

// E2EValidatorFlags contains a list of the validator feature flags to be tested in E2E.
Expand All @@ -194,6 +199,7 @@ var BeaconChainFlags = append(deprecatedBeaconFlags, append(deprecatedFlags, []c
PraterTestnet,
SepoliaTestnet,
Mainnet,
PolymerDevnetMode,
disablePeerScorer,
disableBroadcastSlashingFlag,
enableSlasherFlag,
Expand Down
12 changes: 6 additions & 6 deletions config/params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ type BeaconChainConfig struct {
ZeroHash [32]byte // ZeroHash is used to represent a zeroed out 32 byte array.

// Time parameters constants.
GenesisDelay uint64 `yaml:"GENESIS_DELAY" spec:"true"` // GenesisDelay is the minimum number of seconds to delay starting the Ethereum Beacon Chain genesis. Must be at least 1 second.
MinAttestationInclusionDelay primitives.Slot `yaml:"MIN_ATTESTATION_INCLUSION_DELAY" spec:"true"` // MinAttestationInclusionDelay defines how many slots validator has to wait to include attestation for beacon block.
SecondsPerSlot uint64 `yaml:"SECONDS_PER_SLOT" spec:"true"` // SecondsPerSlot is how many seconds are in a single slot.
SlotsPerEpoch primitives.Slot `yaml:"SLOTS_PER_EPOCH" spec:"true"` // SlotsPerEpoch is the number of slots in an epoch.
SqrRootSlotsPerEpoch primitives.Slot // SqrRootSlotsPerEpoch is a hard coded value where we take the square root of `SlotsPerEpoch` and round down.
GenesisDelay uint64 `yaml:"GENESIS_DELAY" spec:"true"` // GenesisDelay is the minimum number of seconds to delay starting the Ethereum Beacon Chain genesis. Must be at least 1 second.
MinAttestationInclusionDelay primitives.Slot `yaml:"MIN_ATTESTATION_INCLUSION_DELAY" spec:"true"` // MinAttestationInclusionDelay defines how many slots validator has to wait to include attestation for beacon block.
SecondsPerSlot uint64 `yaml:"SECONDS_PER_SLOT" spec:"true"` // SecondsPerSlot is how many seconds are in a single slot.
SlotsPerEpoch primitives.Slot `yaml:"SLOTS_PER_EPOCH" spec:"true"` // SlotsPerEpoch is the number of slots in an epoch.
SqrRootSlotsPerEpoch primitives.Slot `yaml:"SQR_ROOT_SLOTS_PER_EPOCH" spec:"false"` // SqrRootSlotsPerEpoch is a hard coded value where we take the square root of `SlotsPerEpoch` and round down.
MinSeedLookahead primitives.Epoch `yaml:"MIN_SEED_LOOKAHEAD" spec:"true"` // MinSeedLookahead is the duration of randao look ahead seed.
MaxSeedLookahead primitives.Epoch `yaml:"MAX_SEED_LOOKAHEAD" spec:"true"` // MaxSeedLookahead is the duration a validator has to wait for entry and exit in epoch.
EpochsPerEth1VotingPeriod primitives.Epoch `yaml:"EPOCHS_PER_ETH1_VOTING_PERIOD" spec:"true"` // EpochsPerEth1VotingPeriod defines how often the merkle root of deposit receipts get updated in beacon node on per epoch basis.
Expand Down Expand Up @@ -104,7 +104,7 @@ type BeaconChainConfig struct {
MaxVoluntaryExits uint64 `yaml:"MAX_VOLUNTARY_EXITS" spec:"true"` // MaxVoluntaryExits defines the maximum number of validator exits in a block.
MaxWithdrawalsPerPayload uint64 `yaml:"MAX_WITHDRAWALS_PER_PAYLOAD" spec:"true"` // MaxWithdrawalsPerPayload defines the maximum number of withdrawals in a block.
MaxBlsToExecutionChanges uint64 `yaml:"MAX_BLS_TO_EXECUTION_CHANGES" spec:"true"` // MaxBlsToExecutionChanges defines the maximum number of BLS-to-execution-change objects in a block.
MaxValidatorsPerWithdrawalsSweep uint64 `yaml:"MAX_VALIDATORS_PER_WITHDRAWALS_SWEEP" spec:"true"` //MaxValidatorsPerWithdrawalsSweep bounds the size of the sweep searching for withdrawals per slot.
MaxValidatorsPerWithdrawalsSweep uint64 `yaml:"MAX_VALIDATORS_PER_WITHDRAWALS_SWEEP" spec:"true"` // MaxValidatorsPerWithdrawalsSweep bounds the size of the sweep searching for withdrawals per slot.

// BLS domain values.
DomainBeaconProposer [4]byte `yaml:"DOMAIN_BEACON_PROPOSER" spec:"true"` // DomainBeaconProposer defines the BLS signature domain for beacon proposal verification.
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ require (
github.com/prysmaticlabs/go-bitfield v0.0.0-20210809151128-385d8c5e3fb7
github.com/prysmaticlabs/prombbolt v0.0.0-20210126082820-9b7adba6db7c
github.com/prysmaticlabs/protoc-gen-go-cast v0.0.0-20230228205207-28762a7b9294
github.com/prysmaticlabs/prysm/v3 v3.2.2
github.com/r3labs/sse v0.0.0-20210224172625-26fe804710bc
github.com/rs/cors v1.7.0
github.com/schollz/progressbar/v3 v3.3.4
Expand Down Expand Up @@ -101,7 +102,6 @@ require (
github.com/VictoriaMetrics/fastcache v1.12.0 // indirect
github.com/benbjohnson/clock v1.3.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/cp v1.1.1 // indirect
github.com/cespare/xxhash v1.1.0 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/chzyer/readline v1.5.1 // indirect
Expand Down
3 changes: 2 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ github.com/cenkalti/backoff v2.2.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QH
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/cespare/cp v0.1.0/go.mod h1:SOGHArjBr4JWaSDEVpWpo/hNg6RoKrls6Oh40hiwW+s=
github.com/cespare/cp v1.1.1 h1:nCb6ZLdB7NRaqsm91JtQTAme2SKJzXVsdPIPkyJr1MU=
github.com/cespare/cp v1.1.1/go.mod h1:SOGHArjBr4JWaSDEVpWpo/hNg6RoKrls6Oh40hiwW+s=
github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko=
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
Expand Down Expand Up @@ -1075,6 +1074,8 @@ github.com/prysmaticlabs/prombbolt v0.0.0-20210126082820-9b7adba6db7c h1:9PHRCuO
github.com/prysmaticlabs/prombbolt v0.0.0-20210126082820-9b7adba6db7c/go.mod h1:ZRws458tYHS/Zs936OQ6oCrL+Ict5O4Xpwve1UQ6C9M=
github.com/prysmaticlabs/protoc-gen-go-cast v0.0.0-20230228205207-28762a7b9294 h1:q9wE0ZZRdTUAAeyFP/w0SwBEnCqlVy2+on6X2/e+eAU=
github.com/prysmaticlabs/protoc-gen-go-cast v0.0.0-20230228205207-28762a7b9294/go.mod h1:ZVEbRdnMkGhp/pu35zq4SXxtvUwWK0J1MATtekZpH2Y=
github.com/prysmaticlabs/prysm/v3 v3.2.2 h1:8lC6vX4F/gVPVOrOZ49SkHjxZIpl0XLziIvlFKdyLwA=
github.com/prysmaticlabs/prysm/v3 v3.2.2/go.mod h1:tk/LvCJpiq/EpMPkSJwE0OYBLnXOiMktEN+Xt1IIKkE=
github.com/quic-go/qpack v0.4.0 h1:Cr9BXA1sQS2SmDUWjSofMPNKmvF6IiIfDRmgU0w1ZCo=
github.com/quic-go/qpack v0.4.0/go.mod h1:UZVnYIfi5GRk+zI9UMaCPsmZ2xKJP7XBUvVyT1Knj9A=
github.com/quic-go/qtls-go1-19 v0.3.2 h1:tFxjCFcTQzK+oMxG6Zcvp4Dq8dx4yD3dDiIiyc86Z5U=
Expand Down
3 changes: 1 addition & 2 deletions proto/eth/v2/beacon_chain.pb.gw.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
//go:build ignore
// +build ignore

package ignore
package ignore
3 changes: 1 addition & 2 deletions proto/eth/v2/withdrawals.pb.gw.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
//go:build ignore
// +build ignore

package ignore
package ignore