Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/devel' into devel+classic
Browse files Browse the repository at this point in the history
Conflicts:
  core/blockchain.go
  • Loading branch information
meowsbits committed Oct 16, 2023
2 parents 7a1e9c0 + 9e42b70 commit 9c7e85e
Show file tree
Hide file tree
Showing 95 changed files with 1,359 additions and 806 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
- name: Maximize build space
uses: AdityaGarg8/remove-unwanted-software@v1
with:
remove-dotnet: 'true'
remove-android: 'true'
remove-haskell: 'true'

- name: Checkout
uses: actions/checkout@v3
with:
Expand Down
62 changes: 62 additions & 0 deletions .github/workflows/test-integration-caplin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Consensus specification tests
on:
push:
branches:
- devel
- alpha
- 'release/**'
pull_request:
branches:
- devel
- alpha
- 'release/**'
types:
- opened
- reopened
- synchronize
- ready_for_review

jobs:
tests:
strategy:
matrix:
os: [ ubuntu-20.04, macos-11 ] # list of os: https://github.com/actions/virtual-environments
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: '1.20'
- name: Install dependencies on Linux
if: runner.os == 'Linux'
run: sudo apt update && sudo apt install build-essential

- name: test-integration-caplin
run: cd cl/spectest && make tests && make mainnet

tests-windows:
strategy:
matrix:
os: [ windows-2022 ]
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: '1.20'

- uses: actions/cache@v3
with:
path: |
C:\ProgramData\chocolatey\lib\mingw
C:\ProgramData\chocolatey\lib\cmake
key: chocolatey-${{ matrix.os }}
- name: Install dependencies
run: |
choco upgrade mingw -y --no-progress --version 11.2.0.07112021
choco install cmake -y --no-progress --version 3.23.1
- name: test-integration-caplin
run: cd ./cl/spectest/ && .\wmake.ps1 Tests Mainnet
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ COPY --from=builder /app/build/bin/sentry /usr/local/bin/sentry
COPY --from=builder /app/build/bin/state /usr/local/bin/state
COPY --from=builder /app/build/bin/txpool /usr/local/bin/txpool
COPY --from=builder /app/build/bin/verkle /usr/local/bin/verkle
COPY --from=builder /app/build/bin/caplin-phase1 /usr/local/bin/caplin-phase1
COPY --from=builder /app/build/bin/caplin /usr/local/bin/caplin
COPY --from=builder /app/build/bin/caplin-regression /usr/local/bin/caplin-regression


Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.debian
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ COPY --from=builder /app/build/bin/sentry /usr/local/bin/sentry
COPY --from=builder /app/build/bin/state /usr/local/bin/state
COPY --from=builder /app/build/bin/txpool /usr/local/bin/txpool
COPY --from=builder /app/build/bin/verkle /usr/local/bin/verkle
COPY --from=builder /app/build/bin/caplin-phase1 /usr/local/bin/caplin-phase1
COPY --from=builder /app/build/bin/caplin /usr/local/bin/caplin
COPY --from=builder /app/build/bin/caplin-regression /usr/local/bin/caplin-regression

EXPOSE 8545 \
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ COMMANDS += txpool
COMMANDS += verkle
COMMANDS += evm
COMMANDS += sentinel
COMMANDS += caplin-phase1
COMMANDS += caplin
COMMANDS += caplin-regression


Expand Down
3 changes: 1 addition & 2 deletions accounts/abi/bind/backends/simulated.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (

"github.com/ledgerwatch/erigon-lib/chain"
libcommon "github.com/ledgerwatch/erigon-lib/common"
"github.com/ledgerwatch/erigon-lib/common/fixedgas"
"github.com/ledgerwatch/erigon-lib/common/hexutility"
"github.com/ledgerwatch/erigon-lib/kv"
state2 "github.com/ledgerwatch/erigon-lib/state"
Expand Down Expand Up @@ -174,7 +173,7 @@ func (b *SimulatedBackend) emptyPendingBlock() {
b.pendingBlock = blockChain.Blocks[0]
b.pendingReceipts = blockChain.Receipts[0]
b.pendingHeader = blockChain.Headers[0]
b.gasPool = new(core.GasPool).AddGas(b.pendingHeader.GasLimit).AddBlobGas(fixedgas.MaxBlobGasPerBlock)
b.gasPool = new(core.GasPool).AddGas(b.pendingHeader.GasLimit).AddBlobGas(b.m.ChainConfig.GetMaxBlobGasPerBlock())
if b.pendingReaderTx != nil {
b.pendingReaderTx.Rollback()
}
Expand Down
4 changes: 4 additions & 0 deletions cl/cltypes/clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,7 @@ func (*KZGCommitment) Clone() clonable.Clonable {
func (*Eth1Header) Clone() clonable.Clonable {
return &Eth1Header{}
}

func (*Withdrawal) Clone() clonable.Clonable {
return &Withdrawal{}
}
24 changes: 12 additions & 12 deletions cl/cltypes/eth1_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ type Eth1Block struct {
Extra *solid.ExtraData `json:"extra_data"`
BaseFeePerGas libcommon.Hash `json:"base_fee_per_gas"`
// Extra fields
BlockHash libcommon.Hash `json:"block_hash"`
Transactions *solid.TransactionsSSZ `json:"transactions"`
Withdrawals *solid.ListSSZ[*types.Withdrawal] `json:"withdrawals,omitempty"`
BlobGasUsed uint64 `json:"blob_gas_used,omitempty"`
ExcessBlobGas uint64 `json:"excess_blob_gas,omitempty"`
BlockHash libcommon.Hash `json:"block_hash"`
Transactions *solid.TransactionsSSZ `json:"transactions"`
Withdrawals *solid.ListSSZ[*Withdrawal] `json:"withdrawals,omitempty"`
BlobGasUsed uint64 `json:"blob_gas_used,omitempty"`
ExcessBlobGas uint64 `json:"excess_blob_gas,omitempty"`
// internals
version clparams.StateVersion
beaconCfg *clparams.BeaconChainConfig
Expand Down Expand Up @@ -70,7 +70,7 @@ func NewEth1BlockFromHeaderAndBody(header *types.Header, body *types.RawBody, be
BaseFeePerGas: baseFee32,
BlockHash: header.Hash(),
Transactions: solid.NewTransactionsSSZFromTransactions(body.Transactions),
Withdrawals: solid.NewStaticListSSZFromList(body.Withdrawals, int(beaconCfg.MaxWithdrawalsPerPayload), 44),
Withdrawals: solid.NewStaticListSSZFromList(convertExecutionWithdrawalsToConsensusWithdrawals(body.Withdrawals), int(beaconCfg.MaxWithdrawalsPerPayload), 44),
beaconCfg: beaconCfg,
}

Expand Down Expand Up @@ -145,7 +145,7 @@ func (b *Eth1Block) EncodingSizeSSZ() (size int) {

if b.version >= clparams.CapellaVersion {
if b.Withdrawals == nil {
b.Withdrawals = solid.NewStaticListSSZ[*types.Withdrawal](int(b.beaconCfg.MaxWithdrawalsPerPayload), 44)
b.Withdrawals = solid.NewStaticListSSZ[*Withdrawal](int(b.beaconCfg.MaxWithdrawalsPerPayload), 44)
}
size += b.Withdrawals.EncodingSizeSSZ() + 4
}
Expand All @@ -161,7 +161,7 @@ func (b *Eth1Block) EncodingSizeSSZ() (size int) {
func (b *Eth1Block) DecodeSSZ(buf []byte, version int) error {
b.Extra = solid.NewExtraData()
b.Transactions = &solid.TransactionsSSZ{}
b.Withdrawals = solid.NewStaticListSSZ[*types.Withdrawal](int(b.beaconCfg.MaxWithdrawalsPerPayload), 44)
b.Withdrawals = solid.NewStaticListSSZ[*Withdrawal](int(b.beaconCfg.MaxWithdrawalsPerPayload), 44)
b.version = clparams.StateVersion(version)
return ssz2.UnmarshalSSZ(buf, version, b.getSchema()...)
}
Expand Down Expand Up @@ -202,8 +202,8 @@ func (b *Eth1Block) RlpHeader() (*types.Header, error) {
withdrawalsHash = new(libcommon.Hash)
// extract all withdrawals from itearable list
withdrawals := make([]*types.Withdrawal, b.Withdrawals.Len())
b.Withdrawals.Range(func(idx int, w *types.Withdrawal, _ int) bool {
withdrawals[idx] = w
b.Withdrawals.Range(func(idx int, w *Withdrawal, _ int) bool {
withdrawals[idx] = convertConsensusWithdrawalToExecutionWithdrawal(w)
return true
})
*withdrawalsHash = types.DeriveSha(types.Withdrawals(withdrawals))
Expand Down Expand Up @@ -251,8 +251,8 @@ func (b *Eth1Block) Version() clparams.StateVersion {
// Body returns the equivalent raw body (only eth1 body section).
func (b *Eth1Block) Body() *types.RawBody {
withdrawals := make([]*types.Withdrawal, b.Withdrawals.Len())
b.Withdrawals.Range(func(idx int, w *types.Withdrawal, _ int) bool {
withdrawals[idx] = w
b.Withdrawals.Range(func(idx int, w *Withdrawal, _ int) bool {
withdrawals[idx] = convertConsensusWithdrawalToExecutionWithdrawal(w)
return true
})
return &types.RawBody{
Expand Down
72 changes: 72 additions & 0 deletions cl/cltypes/withdrawal.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package cltypes

import (
"fmt"

libcommon "github.com/ledgerwatch/erigon-lib/common"
"github.com/ledgerwatch/erigon-lib/common/length"
"github.com/ledgerwatch/erigon-lib/types/ssz"
"github.com/ledgerwatch/erigon/cl/merkle_tree"
"github.com/ledgerwatch/erigon/core/types"
)

type Withdrawal struct {
Index uint64 `json:"index"` // monotonically increasing identifier issued by consensus layer
Validator uint64 `json:"validatorIndex"` // index of validator associated with withdrawal
Address libcommon.Address `json:"address"` // target address for withdrawn ether
Amount uint64 `json:"amount"` // value of withdrawal in GWei
}

func (obj *Withdrawal) EncodeSSZ(buf []byte) ([]byte, error) {
buf = append(buf, ssz.Uint64SSZ(obj.Index)...)
buf = append(buf, ssz.Uint64SSZ(obj.Validator)...)
buf = append(buf, obj.Address[:]...)
buf = append(buf, ssz.Uint64SSZ(obj.Amount)...)
return buf, nil
}

func (obj *Withdrawal) DecodeSSZ(buf []byte, _ int) error {
if len(buf) < obj.EncodingSizeSSZ() {
return fmt.Errorf("[Withdrawal] err: %s", ssz.ErrLowBufferSize)
}
obj.Index = ssz.UnmarshalUint64SSZ(buf)
obj.Validator = ssz.UnmarshalUint64SSZ(buf[8:])
copy(obj.Address[:], buf[16:])
obj.Amount = ssz.UnmarshalUint64SSZ(buf[36:])
return nil
}

func (obj *Withdrawal) EncodingSizeSSZ() int {
// Validator Index (8 bytes) + Index (8 bytes) + Amount (8 bytes) + address length
return 24 + length.Addr
}

func (obj *Withdrawal) HashSSZ() ([32]byte, error) { // the [32]byte is temporary
return merkle_tree.HashTreeRoot(obj.Index, obj.Validator, obj.Address[:], obj.Amount)
}

func convertExecutionWithdrawalToConsensusWithdrawal(executionWithdrawal *types.Withdrawal) *Withdrawal {
return &Withdrawal{
Index: executionWithdrawal.Index,
Validator: executionWithdrawal.Validator,
Address: executionWithdrawal.Address,
Amount: executionWithdrawal.Amount,
}
}

func convertConsensusWithdrawalToExecutionWithdrawal(consensusWithdrawal *Withdrawal) *types.Withdrawal {
return &types.Withdrawal{
Index: consensusWithdrawal.Index,
Validator: consensusWithdrawal.Validator,
Address: consensusWithdrawal.Address,
Amount: consensusWithdrawal.Amount,
}
}

func convertExecutionWithdrawalsToConsensusWithdrawals(executionWithdrawal []*types.Withdrawal) []*Withdrawal {
ret := make([]*Withdrawal, len(executionWithdrawal))
for i, w := range executionWithdrawal {
ret[i] = convertExecutionWithdrawalToConsensusWithdrawal(w)
}
return ret
}
4 changes: 4 additions & 0 deletions cl/persistence/block_saver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ func (m *mockEngine) ForkChoiceUpdate(finalized libcommon.Hash, head libcommon.H
panic("unimplemented")
}

func (m *mockEngine) FrozenBlocks() uint64 {
panic("unimplemented")
}

func (m *mockEngine) NewPayload(payload *cltypes.Eth1Block, beaconParentRoot *libcommon.Hash) (bool, error) {
panic("unimplemented")
}
Expand Down
Loading

0 comments on commit 9c7e85e

Please sign in to comment.