diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 000000000000..491ea263b714 --- /dev/null +++ b/.github/workflows/docker.yml @@ -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 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000000..9301b31f06e5 --- /dev/null +++ b/Dockerfile @@ -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 diff --git a/beacon-chain/blockchain/service.go b/beacon-chain/blockchain/service.go index 60356022e5f7..dd41c33c7ed5 100644 --- a/beacon-chain/blockchain/service.go +++ b/beacon-chain/blockchain/service.go @@ -62,6 +62,7 @@ type Service struct { clockSetter startup.ClockSetter clockWaiter startup.ClockWaiter syncComplete chan struct{} + processAttestationsLock sync.Mutex lastPublishedLightClientEpoch primitives.Epoch } diff --git a/beacon-chain/core/epoch/precompute/BUILD.bazel b/beacon-chain/core/epoch/precompute/BUILD.bazel index 3d316080236a..a51d6d9e990c 100644 --- a/beacon-chain/core/epoch/precompute/BUILD.bazel +++ b/beacon-chain/core/epoch/precompute/BUILD.bazel @@ -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", diff --git a/beacon-chain/core/epoch/precompute/justification_finalization.go b/beacon-chain/core/epoch/precompute/justification_finalization.go index 4aa63cfd2673..1120a0e05d0d 100644 --- a/beacon-chain/core/epoch/precompute/justification_finalization.go +++ b/beacon-chain/core/epoch/precompute/justification_finalization.go @@ -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" @@ -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 diff --git a/beacon-chain/execution/service.go b/beacon-chain/execution/service.go index 58393ac8f73c..0a8e447788e1 100644 --- a/beacon-chain/execution/service.go +++ b/beacon-chain/execution/service.go @@ -6,6 +6,7 @@ package execution import ( "context" "fmt" + "github.com/prysmaticlabs/prysm/v4/config/features" "math/big" "reflect" "runtime/debug" @@ -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) @@ -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) diff --git a/beacon-chain/p2p/pubsub_filter.go b/beacon-chain/p2p/pubsub_filter.go index b9f42c1e3b13..03425ef5ec42 100644 --- a/beacon-chain/p2p/pubsub_filter.go +++ b/beacon-chain/p2p/pubsub_filter.go @@ -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" ) @@ -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 diff --git a/beacon-chain/rpc/prysm/v1alpha1/debug/p2p.go b/beacon-chain/rpc/prysm/v1alpha1/debug/p2p.go index 1e0b90c27857..1dab09b3af59 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/debug/p2p.go +++ b/beacon-chain/rpc/prysm/v1alpha1/debug/p2p.go @@ -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" @@ -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 := ðpb.DebugPeerResponse_PeerInfo{ - Protocols: protocol.ConvertToStrings(protocols), + Protocols: sProtocols, FaultCount: uint64(resp), ProtocolVersion: pVersion, AgentVersion: aVersion, diff --git a/config/features/config.go b/config/features/config.go index 637a31d47916..b7dd97a197a2 100644 --- a/config/features/config.go +++ b/config/features/config.go @@ -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 @@ -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 @@ -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 diff --git a/config/features/flags.go b/config/features/flags.go index bddc4a1569b0..d4cbde083c14 100644 --- a/config/features/flags.go +++ b/config/features/flags.go @@ -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", @@ -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. @@ -194,6 +199,7 @@ var BeaconChainFlags = append(deprecatedBeaconFlags, append(deprecatedFlags, []c PraterTestnet, SepoliaTestnet, Mainnet, + PolymerDevnetMode, disablePeerScorer, disableBroadcastSlashingFlag, enableSlasherFlag, diff --git a/config/params/config.go b/config/params/config.go index 493370c68393..884d7e1e6485 100644 --- a/config/params/config.go +++ b/config/params/config.go @@ -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. @@ -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. diff --git a/go.mod b/go.mod index dfbef65426d2..50b584c78ec9 100644 --- a/go.mod +++ b/go.mod @@ -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 @@ -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 diff --git a/go.sum b/go.sum index 52a9d86689ca..4c1dc31c0f2d 100644 --- a/go.sum +++ b/go.sum @@ -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= @@ -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= diff --git a/proto/eth/v2/beacon_chain.pb.gw.go b/proto/eth/v2/beacon_chain.pb.gw.go index cdd03643f0c7..b76fb6098a37 100755 --- a/proto/eth/v2/beacon_chain.pb.gw.go +++ b/proto/eth/v2/beacon_chain.pb.gw.go @@ -1,4 +1,3 @@ -//go:build ignore // +build ignore -package ignore +package ignore \ No newline at end of file diff --git a/proto/eth/v2/withdrawals.pb.gw.go b/proto/eth/v2/withdrawals.pb.gw.go index cdd03643f0c7..b76fb6098a37 100755 --- a/proto/eth/v2/withdrawals.pb.gw.go +++ b/proto/eth/v2/withdrawals.pb.gw.go @@ -1,4 +1,3 @@ -//go:build ignore // +build ignore -package ignore +package ignore \ No newline at end of file