Skip to content

Commit

Permalink
caplin on mekong devnet-4 (#13296)
Browse files Browse the repository at this point in the history
Configs:
https://github.com/ethpandaops/mekong-devnets/tree/master/network-configs/devnet-0/metadata
```
wget https://github.com/ethpandaops/mekong-devnets/raw/refs/heads/master/network-configs/devnet-0/metadata/genesis.ssz \
https://raw.githubusercontent.com/ethpandaops/mekong-devnets/refs/heads/master/network-configs/devnet-0/metadata/genesis.json \
https://raw.githubusercontent.com/ethpandaops/mekong-devnets/refs/heads/master/network-configs/devnet-0/metadata/config.yaml
```

Example Run:
```
./build/bin/erigon init --datadir=data/ genesis.json
```

```
erigon/build/bin/erigon --datadir=data/ --networkid=7078815900 \
--http --http.api=engine,net,eth \
--bootnodes="enode://125d2dddd0dc0d34b526910d49592545a1e4fe25139be9d9e0eed396211dbd37aa0c0a7fa0444c315803d814e743f890529b58b9261289d5303e16477c216b39@157.230.225.158:30303?discport=30303,enode://508bff69cbb852337cfbf3db9e58fe66ec3254e6a3960c0ef266a2ab1ea78e12f101bba51e3d2e066947a0b9b315e5b26009af81584510394c1b87a5908dca7b@137.184.72.127:30303?discport=30303,enode://b273c662dd15148162c23a5c8407d3d5dbb35fb331ae0c1c3a80c6bfa2bbe077683b28c0cd59f7a482efc00a64a09273eb4767a173441a79b833fdf705d331ae@152.42.247.97:30303?discport=30303" \
--log.console.verbosity=4 \
--caplin.custom-config=config.yaml \
--caplin.custom-genesis=genesis.ssz \
--sentinel.bootnodes=enr:-Iq4QB2ny1q6gkBjqNRU_e-GTbpcJQcI4i3cIZDea0mnAzGgbUTKH8j81g9PRl_-m40F1V4GFBlqZElrcbGnUj9AjGeGAZL8bgmtgmlkgnY0gmlwhJ3m4Z6Jc2VjcDI1NmsxoQJJ3h8aUO3GJHv-bdvHtsQZ2OEisutelYfGjXO4lSg8BYN1ZHCCIzI,enr:-LK4QF2XD_Fe5H9QMVVwBoDs6P_37eURcFvNTcLzOc60p_XlDKIBleMgudA7nltZ7TyAiOuY0BSQzHsdv5iUs7sFyWQEh2F0dG5ldHOIAwAAAAAAAACEZXRoMpDY3UMGYGN2JAABAAAAAAAAgmlkgnY0gmlwhJ3m4Z6Jc2VjcDI1NmsxoQJJ7y6LF_to7NYQd3BVRW1840gm5r1Lm3lfAfC9Wqmw8YN0Y3CCIyiDdWRwgiMo,enr:-Mm4QPtT8J4rpYkixx-COebnEPreuWv9OpgOGOvM01hqZ19eeySxCxOEEVHl2r2c0BYwBuct_yZhvkLqUQatRORlIP4Bh2F0dG5ldHOIAAAAAAAAAACDY3NjBIRldGgykNjdQwZgY3YkAAEAAAAAAACCaWSCdjSCaXCEibhIf4RxdWljgiMpiXNlY3AyNTZrMaEDjight_62uShKNt4IorH13hfqm7kZzVyFxXKI_qDlsTGIc3luY25ldHMAg3RjcIIjKIN1ZHCCIyg,enr:-Mm4QBL6auezk-Zi385j0PyjkzGwQJW7TdOFZKGZMKTGRkI4fxTSTiHLe7kTvdjhBq4kgjPXvUnFiXR6AisA8a0w2lQBh2F0dG5ldHOIAAAAAAAAAACDY3NjBIRldGgykNjdQwZgY3YkAAEAAAAAAACCaWSCdjSCaXCEmCr3YYRxdWljgiMpiXNlY3AyNTZrMaEDJ4xl2Our0Y7OKsSDX9f908HznXm3PKzmC9zD8OB2d0mIc3luY25ldHMAg3RjcIIjKIN1ZHCCIyg
```
  • Loading branch information
domiwei authored Jan 16, 2025
1 parent e41d087 commit f55e05a
Show file tree
Hide file tree
Showing 32 changed files with 251 additions and 103 deletions.
12 changes: 9 additions & 3 deletions cl/clparams/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,13 @@ func (b *BeaconChainConfig) RoundSlotToVotePeriod(slot uint64) uint64 {
}

func (b *BeaconChainConfig) GetCurrentStateVersion(epoch uint64) StateVersion {
forkEpochList := []uint64{b.AltairForkEpoch, b.BellatrixForkEpoch, b.CapellaForkEpoch, b.DenebForkEpoch}
forkEpochList := []uint64{
b.AltairForkEpoch,
b.BellatrixForkEpoch,
b.CapellaForkEpoch,
b.DenebForkEpoch,
b.ElectraForkEpoch,
}
stateVersion := Phase0Version
for _, forkEpoch := range forkEpochList {
if forkEpoch > epoch {
Expand Down Expand Up @@ -834,8 +840,8 @@ var MainnetBeaconConfig BeaconChainConfig = BeaconChainConfig{
TargetNumberOfPeers: 70,

// Electra
MinPerEpochChurnLimitElectra: 128000000000,
MaxPerEpochActivationExitChurnLimit: 256000000000,
MinPerEpochChurnLimitElectra: 128_000_000_000,
MaxPerEpochActivationExitChurnLimit: 256_000_000_000,
MaxDepositRequestsPerPayload: 8192,
MaxWithdrawalRequestsPerPayload: 16,
MaxConsolidationRequestsPerPayload: 1,
Expand Down
35 changes: 19 additions & 16 deletions cl/cltypes/beacon_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -536,25 +536,28 @@ func (b *BeaconBody) GetExecutionRequests() *ExecutionRequests {
}

func (b *BeaconBody) GetExecutionRequestsList() []hexutility.Bytes {
ret := []hexutility.Bytes{}
r := b.ExecutionRequests
for requestType, requests := range map[byte]ssz.EncodableSSZ{
b.beaconCfg.DepositRequestType: r.Deposits,
b.beaconCfg.WithdrawalRequestType: r.Withdrawals,
b.beaconCfg.ConsolidationRequestType: r.Consolidations,
if r == nil {
return nil
}
ret := []hexutility.Bytes{}
for _, r := range []struct {
typ byte
requests ssz.EncodableSSZ
}{
{b.beaconCfg.DepositRequestType, r.Deposits},
{b.beaconCfg.WithdrawalRequestType, r.Withdrawals},
{b.beaconCfg.ConsolidationRequestType, r.Consolidations},
} {
if requests != nil {
ssz, err := r.Deposits.EncodeSSZ(nil)
if err != nil {
log.Warn("Error encoding deposits", "err", err)
return nil
}
if len(ssz) == 0 {
continue
}
// type + ssz
ret = append(ret, append(hexutility.Bytes{requestType}, ssz...))
ssz, err := r.requests.EncodeSSZ([]byte{})
if err != nil {
log.Warn("Error encoding deposits", "err", err)
return nil
}
// type + ssz
// ret = append(ret, append(hexutility.Bytes{requestType}, ssz...))
// in Mekong devnet-4, we don't need to add type
ret = append(ret, ssz)
}
return ret
}
Expand Down
2 changes: 1 addition & 1 deletion cl/cltypes/beacon_block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func TestBeaconBody(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, libcommon.HexToHash("918d1ee08d700e422fcce6319cd7509b951d3ebfb1a05291aab9466b7e9826fc"), libcommon.Hash(root3))

_, err = body.ExecutionPayload.RlpHeader(&libcommon.Hash{})
_, err = body.ExecutionPayload.RlpHeader(&libcommon.Hash{}, libcommon.Hash{})
assert.NoError(t, err)

p, err := body.ExecutionPayload.PayloadHeader()
Expand Down
15 changes: 7 additions & 8 deletions cl/cltypes/beacon_kzgcommitment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,19 @@
// You should have received a copy of the GNU Lesser General Public License
// along with Erigon. If not, see <http://www.gnu.org/licenses/>.

package cltypes_test
package cltypes

import (
"testing"

"github.com/erigontech/erigon/cl/cltypes"
"github.com/erigontech/erigon/cl/merkle_tree"
"github.com/stretchr/testify/require"
)

func TestKZGCommitmentCopy(t *testing.T) {
require := require.New(t)

commitment := cltypes.KZGCommitment{}
commitment := KZGCommitment{}
commitment[0] = 1
commitmentCopy := commitment.Copy()

Expand All @@ -40,7 +39,7 @@ func TestKZGCommitmentCopy(t *testing.T) {
func TestKZGCommitmentEncodeSSZ(t *testing.T) {
require := require.New(t)

commitment := cltypes.KZGCommitment{}
commitment := KZGCommitment{}
commitment[0] = 1

encoded, err := commitment.EncodeSSZ([]byte{})
Expand All @@ -53,22 +52,22 @@ func TestKZGCommitmentEncodeSSZ(t *testing.T) {
func TestKZGCommitmentDecodeSSZ(t *testing.T) {
require := require.New(t)

commitment := cltypes.KZGCommitment{}
commitment := KZGCommitment{}
encoded := append([]byte{}, commitment[:]...)
encoded[0] = 1

err := commitment.DecodeSSZ(encoded, 0)
require.NoError(err, "Error decoding KZGCommitment")

expected := cltypes.KZGCommitment{}
expected := KZGCommitment{}
expected[0] = 1
require.Equal(commitment, expected, "KZGCommitment DecodeSSZ did not produce the expected result")
}

func TestKZGCommitmentEncodingSizeSSZ(t *testing.T) {
require := require.New(t)

commitment := cltypes.KZGCommitment{}
commitment := KZGCommitment{}
encodingSize := commitment.EncodingSizeSSZ()

require.Equal(encodingSize, 48, "KZGCommitment EncodingSizeSSZ did not return the expected size")
Expand All @@ -77,7 +76,7 @@ func TestKZGCommitmentEncodingSizeSSZ(t *testing.T) {
func TestKZGCommitmentHashSSZ(t *testing.T) {
require := require.New(t)

commitment := cltypes.KZGCommitment{}
commitment := KZGCommitment{}
commitment[0] = 1

hash, err := commitment.HashSSZ()
Expand Down
6 changes: 5 additions & 1 deletion cl/cltypes/eth1_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ func (b *Eth1Block) getSchema() []interface{} {
}

// RlpHeader returns the equivalent types.Header struct with RLP-based fields.
func (b *Eth1Block) RlpHeader(parentRoot *libcommon.Hash) (*types.Header, error) {
func (b *Eth1Block) RlpHeader(parentRoot *libcommon.Hash, executionReqHash libcommon.Hash) (*types.Header, error) {
// Reverse the order of the bytes in the BaseFeePerGas array and convert it to a big integer.
reversedBaseFeePerGas := libcommon.Copy(b.BaseFeePerGas[:])
for i, j := 0, len(reversedBaseFeePerGas)-1; i < j; i, j = i+1, j-1 {
Expand Down Expand Up @@ -362,6 +362,10 @@ func (b *Eth1Block) RlpHeader(parentRoot *libcommon.Hash) (*types.Header, error)
header.ExcessBlobGas = &excessBlobGas
}

if b.version >= clparams.ElectraVersion {
header.RequestsHash = &executionReqHash
}

// If the header hash does not match the block hash, return an error.
if header.Hash() != b.BlockHash {
return nil, fmt.Errorf("cannot derive rlp header: mismatching hash: %s != %s, %d", header.Hash(), b.BlockHash, header.Number)
Expand Down
12 changes: 12 additions & 0 deletions cl/cltypes/execution_requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ package cltypes
import (
"encoding/json"

"github.com/erigontech/erigon-lib/common"
"github.com/erigontech/erigon-lib/common/hexutility"
"github.com/erigontech/erigon-lib/types/clonable"
"github.com/erigontech/erigon/cl/clparams"
"github.com/erigontech/erigon/cl/cltypes/solid"
"github.com/erigontech/erigon/cl/merkle_tree"
ssz2 "github.com/erigontech/erigon/cl/ssz"
"github.com/erigontech/erigon/core/types"
)

var (
Expand Down Expand Up @@ -80,3 +83,12 @@ func (e *ExecutionRequests) UnmarshalJSON(b []byte) error {
e.Consolidations = c.Consolidations
return nil
}

func ComputeExecutionRequestHash(executionRequests []hexutility.Bytes) common.Hash {
requests := make(types.FlatRequests, len(types.KnownRequestTypes))
for i, r := range types.KnownRequestTypes {
requests[i] = types.FlatRequest{Type: r, RequestData: executionRequests[i]}
}
rh := requests.Hash()
return *rh
}
1 change: 1 addition & 0 deletions cl/cltypes/solid/attestation.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ func (s *SingleAttestation) EncodeSSZ(dst []byte) ([]byte, error) {
}

func (s *SingleAttestation) DecodeSSZ(buf []byte, version int) error {
s.Data = &AttestationData{}
return ssz2.UnmarshalSSZ(buf, version, &s.CommitteeIndex, &s.AttesterIndex, s.Data, s.Signature[:])
}

Expand Down
4 changes: 2 additions & 2 deletions cl/phase1/core/state/cache_accessors.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,11 +405,11 @@ func (b *CachingBeaconState) GetAttestingIndicies(
if aggregationBits.GetBitAt(committeeOffset + i) {
attesters = append(attesters, member)
}
committeeOffset += len(committee)
}
committeeOffset += len(committee)
}
if committeeOffset != aggrBitsLen {
return nil, errors.New("GetAttestingIndicies: aggregation bits length does not match committee length")
return nil, fmt.Errorf("GetAttestingIndicies: aggregation bits length does not match committee length. agg bits size: %d, committeeOffset: %d", aggrBitsLen, committeeOffset)
}
return attesters, nil
}
Expand Down
2 changes: 1 addition & 1 deletion cl/phase1/core/state/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func GetIndexedAttestation(attestation *solid.Attestation, attestingIndicies []u
return attestingIndicies[i] < attestingIndicies[j]
})
return &cltypes.IndexedAttestation{
AttestingIndices: solid.NewRawUint64List(2048, attestingIndicies),
AttestingIndices: solid.NewRawUint64List(2048*64, attestingIndicies),
Data: attestation.Data,
Signature: attestation.Signature,
}
Expand Down
24 changes: 20 additions & 4 deletions cl/phase1/execution_client/block_collector/block_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"sync"

"github.com/erigontech/erigon-lib/common"
"github.com/erigontech/erigon-lib/common/hexutility"
"github.com/erigontech/erigon-lib/etl"
"github.com/erigontech/erigon-lib/kv/dbutils"
"github.com/erigontech/erigon-lib/log/v3"
Expand Down Expand Up @@ -71,7 +72,7 @@ func (b *blockCollector) AddBlock(block *cltypes.BeaconBlock) error {
b.mu.Lock()
defer b.mu.Unlock()
payload := block.Body.ExecutionPayload
encodedBlock, err := encodeBlock(payload, block.ParentRoot)
encodedBlock, err := encodeBlock(payload, block.ParentRoot, block.Body.GetExecutionRequestsList())
if err != nil {
return err
}
Expand Down Expand Up @@ -103,7 +104,14 @@ func (b *blockCollector) Flush(ctx context.Context) error {
}
version := clparams.StateVersion(v[0])
parentRoot := common.BytesToHash(v[1:33])
v = v[33:]
requestsHash := common.Hash{}
if version >= clparams.ElectraVersion {
// get the requests hash
requestsHash = common.BytesToHash(v[33:65])
v = v[65:]
} else {
v = v[33:]
}
executionPayload := cltypes.NewEth1Block(version, b.beaconChainCfg)
if err := executionPayload.DecodeSSZ(v, int(version)); err != nil {
return err
Expand All @@ -118,7 +126,7 @@ func (b *blockCollector) Flush(ctx context.Context) error {
if executionPayload.BlockNumber == 0 {
return nil
}
header, err := executionPayload.RlpHeader(&parentRoot)
header, err := executionPayload.RlpHeader(&parentRoot, requestsHash)
if err != nil {
b.logger.Warn("bad blocks segment received", "err", err)
return err
Expand Down Expand Up @@ -156,6 +164,7 @@ func (b *blockCollector) Flush(ctx context.Context) error {
if err := b.engine.InsertBlocks(ctx, blocksBatch, true); err != nil {
b.logger.Warn("failed to insert blocks", "err", err)
}
b.logger.Info("[Caplin] Inserted blocks", "progress", blocksBatch[len(blocksBatch)-1].NumberU64())
}
b.size = 0
// Create a new collector
Expand All @@ -165,12 +174,19 @@ func (b *blockCollector) Flush(ctx context.Context) error {
}

// serializes block value
func encodeBlock(payload *cltypes.Eth1Block, parentRoot common.Hash) ([]byte, error) {
func encodeBlock(payload *cltypes.Eth1Block, parentRoot common.Hash, executionRequestsList []hexutility.Bytes) ([]byte, error) {
encodedPayload, err := payload.EncodeSSZ(nil)
if err != nil {
return nil, fmt.Errorf("error encoding execution payload during download: %s", err)
}
if executionRequestsList != nil {
// electra version
requestsHash := cltypes.ComputeExecutionRequestHash(executionRequestsList)
// version + parentRoot + requestsHash + encodedPayload
return utils.CompressSnappy(append([]byte{byte(payload.Version())}, append(append(parentRoot[:], requestsHash[:]...), encodedPayload...)...)), nil
}
// Use snappy compression that the temporary files do not take too much disk.
// version + parentRoot + encodedPayload
return utils.CompressSnappy(append([]byte{byte(payload.Version())}, append(parentRoot[:], encodedPayload...)...)), nil
}

Expand Down
8 changes: 7 additions & 1 deletion cl/phase1/execution_client/execution_client_direct.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
libcommon "github.com/erigontech/erigon-lib/common"
"github.com/erigontech/erigon-lib/common/hexutility"
execution "github.com/erigontech/erigon-lib/gointerfaces/executionproto"
"github.com/erigontech/erigon/cl/clparams"
"github.com/erigontech/erigon/cl/cltypes"
"github.com/erigontech/erigon/cl/monitor"
"github.com/erigontech/erigon/core/types"
Expand Down Expand Up @@ -55,7 +56,12 @@ func (cc *ExecutionClientDirect) NewPayload(
return PayloadStatusValidated, nil
}

header, err := payload.RlpHeader(beaconParentRoot)
var requestsHash libcommon.Hash
if payload.Version() >= clparams.ElectraVersion {
requestsHash = cltypes.ComputeExecutionRequestHash(executionRequestsList)
}

header, err := payload.RlpHeader(beaconParentRoot, requestsHash)
if err != nil {
// invalid block
return PayloadStatusInvalidated, err
Expand Down
3 changes: 1 addition & 2 deletions cl/phase1/forkchoice/fork_graph/fork_graph_disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,10 +264,9 @@ func (f *forkGraphDisk) AddChainSegment(signedBlock *cltypes.SignedBeaconBlock,
// Execute the state
if invalidBlockErr := transition.TransitionState(newState, signedBlock, blockRewardsCollector, fullValidation); invalidBlockErr != nil {
// Add block to list of invalid blocks
log.Warn("Invalid beacon block", "slot", block.Slot, "blockRoot", blockRoot, "reason", invalidBlockErr)
log.Warn("Invalid beacon block", "slot", block.Slot, "blockRoot", libcommon.Bytes2Hex(blockRoot[:]), "reason", invalidBlockErr)
f.badBlocks.Store(libcommon.Hash(blockRoot), struct{}{})
f.currentState = nil

return nil, InvalidBlock, invalidBlockErr
}
f.blockRewards.Store(libcommon.Hash(blockRoot), blockRewardsCollector)
Expand Down
5 changes: 3 additions & 2 deletions cl/phase1/forkchoice/on_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func (f *ForkChoiceStore) ProcessBlockConsensus(ctx context.Context, block *clty
return fmt.Errorf("ProcessBlockConsensus: replay block, status %+v", err)
}
if time.Since(start) > 1*time.Millisecond {
log.Debug("OnBlock", "elapsed", time.Since(start))
log.Debug("OnBlock", "elapsed", time.Since(start), "slot", block.Block.Slot)
}
return nil
}
Expand Down Expand Up @@ -214,6 +214,7 @@ func (f *ForkChoiceStore) OnBlock(ctx context.Context, block *cltypes.SignedBeac
timeStartExec := time.Now()
payloadStatus, err := f.engine.NewPayload(ctx, block.Block.Body.ExecutionPayload, &block.Block.ParentRoot, versionedHashes, executionRequestsList)
monitor.ObserveNewPayloadTime(timeStartExec)
log.Debug("[OnBlock] NewPayload", "status", payloadStatus, "blockSlot", block.Block.Slot)
switch payloadStatus {
case execution_client.PayloadStatusNotValidated:
log.Debug("OnBlock: block is not validated yet", "block", libcommon.Hash(blockRoot))
Expand Down Expand Up @@ -345,7 +346,7 @@ func (f *ForkChoiceStore) OnBlock(ctx context.Context, block *cltypes.SignedBeac
f.validatorMonitor.OnNewBlock(lastProcessedState, block.Block)
}
if !isVerifiedExecutionPayload {
log.Debug("OnBlock", "elapsed", time.Since(start))
log.Debug("OnBlock", "elapsed", time.Since(start), "slot", block.Block.Slot)
}
return nil
}
Expand Down
Loading

0 comments on commit f55e05a

Please sign in to comment.