Skip to content

Commit

Permalink
merge devel
Browse files Browse the repository at this point in the history
  • Loading branch information
AskAlexSharov committed Jan 11, 2024
2 parents a83f9ae + 1ee439e commit 63741dd
Show file tree
Hide file tree
Showing 48 changed files with 651 additions and 349 deletions.
2 changes: 2 additions & 0 deletions cl/beacon/handler/attestation_rewards_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build integration

package handler

import (
Expand Down
2 changes: 2 additions & 0 deletions cl/beacon/handler/commitees_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build integration

package handler

import (
Expand Down
2 changes: 2 additions & 0 deletions cl/beacon/handler/config_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build integration

package handler

import (
Expand Down
2 changes: 2 additions & 0 deletions cl/beacon/handler/duties_attester_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build integration

package handler

import (
Expand Down
2 changes: 2 additions & 0 deletions cl/beacon/handler/duties_proposer_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build integration

package handler

import (
Expand Down
2 changes: 2 additions & 0 deletions cl/beacon/handler/duties_sync_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build integration

package handler

import (
Expand Down
2 changes: 1 addition & 1 deletion cl/beacon/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func (a *ApiHandler) init() {
r.Get("/blinded_blocks/{slot}", http.NotFound)
r.Get("/attestation_data", http.NotFound)
r.Get("/aggregate_attestation", http.NotFound)
r.Post("/aggregate_and_proofs", http.NotFound)
r.Post("/aggregate_and_proofs", a.PostEthV1ValidatorAggregatesAndProof)
r.Post("/beacon_committee_subscriptions", http.NotFound)
r.Post("/sync_committee_subscriptions", http.NotFound)
r.Get("/sync_committee_contribution", http.NotFound)
Expand Down
2 changes: 2 additions & 0 deletions cl/beacon/handler/headers_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build integration

package handler

import (
Expand Down
32 changes: 32 additions & 0 deletions cl/beacon/handler/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,3 +191,35 @@ func (a *ApiHandler) PostEthV1BeaconPoolBlsToExecutionChanges(w http.ResponseWri
// Only write 200
w.WriteHeader(http.StatusOK)
}

func (a *ApiHandler) PostEthV1ValidatorAggregatesAndProof(w http.ResponseWriter, r *http.Request) {
req := []*cltypes.SignedAggregateAndProof{}

if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}

failures := []poolingFailure{}
for _, v := range req {
if err := a.forkchoiceStore.OnAggregateAndProof(v, false); err != nil {
failures = append(failures, poolingFailure{Index: len(failures), Message: err.Error()})
continue
}
// Broadcast to gossip
if a.sentinel != nil {
encodedSSZ, err := v.EncodeSSZ(nil)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
if _, err := a.sentinel.PublishGossip(r.Context(), &sentinel.GossipData{
Data: encodedSSZ,
Name: gossip.TopicNameBeaconAggregateAndProof,
}); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
}
}
}
51 changes: 51 additions & 0 deletions cl/beacon/handler/pool_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build integration

package handler

import (
Expand Down Expand Up @@ -195,3 +197,52 @@ func TestPoolBlsToExecutionChainges(t *testing.T) {
require.Equal(t, msg[0], out.Data[0])
require.Equal(t, msg[1], out.Data[1])
}

func TestPoolAggregatesAndProofs(t *testing.T) {
msg := []*cltypes.SignedAggregateAndProof{
{
Message: &cltypes.AggregateAndProof{
Aggregate: solid.NewAttestionFromParameters([]byte{1, 2}, solid.NewAttestationData(), libcommon.Bytes96{3, 45, 6}),
},
Signature: libcommon.Bytes96{2},
},
{
Message: &cltypes.AggregateAndProof{
Aggregate: solid.NewAttestionFromParameters([]byte{1, 2, 5, 6}, solid.NewAttestationData(), libcommon.Bytes96{3, 0, 6}),
},
Signature: libcommon.Bytes96{2, 3, 5},
},
}
// find server
_, _, _, _, _, handler, _, _, _ := setupTestingHandler(t, clparams.Phase0Version)

server := httptest.NewServer(handler.mux)
defer server.Close()
// json
req, err := json.Marshal(msg)
require.NoError(t, err)
// post attester slashing
resp, err := server.Client().Post(server.URL+"/eth/v1/validator/aggregate_and_proofs", "application/json", bytes.NewBuffer(req))
require.NoError(t, err)
defer resp.Body.Close()

require.Equal(t, 200, resp.StatusCode)
// get attester slashings
resp, err = server.Client().Get(server.URL + "/eth/v1/beacon/pool/attestations")
require.NoError(t, err)
defer resp.Body.Close()

require.Equal(t, 200, resp.StatusCode)
out := struct {
Data []*solid.Attestation `json:"data"`
}{
Data: []*solid.Attestation{},
}

err = json.NewDecoder(resp.Body).Decode(&out)
require.NoError(t, err)

require.Equal(t, 2, len(out.Data))
require.Equal(t, msg[0].Message.Aggregate, out.Data[0])
require.Equal(t, msg[1].Message.Aggregate, out.Data[1])
}
2 changes: 2 additions & 0 deletions cl/beacon/handler/validators_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build integration

package handler

import (
Expand Down
2 changes: 1 addition & 1 deletion cl/clparams/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -883,7 +883,7 @@ func chiadoConfig() BeaconChainConfig {
cfg.BellatrixForkVersion = 0x0200006f
cfg.CapellaForkEpoch = 244224
cfg.CapellaForkVersion = 0x0300006f
cfg.DenebForkEpoch = 8265728
cfg.DenebForkEpoch = 516608
cfg.DenebForkVersion = 0x0400006f
cfg.TerminalTotalDifficulty = "231707791542740786049188744689299064356246512"
cfg.DepositContractAddress = "0xb97036A26259B7147018913bD58a774cf91acf25"
Expand Down
1 change: 1 addition & 0 deletions cl/cltypes/solid/attestation.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ func (a *Attestation) UnmarshalJSON(buf []byte) error {
Signature libcommon.Bytes96 `json:"signature"`
Data AttestationData `json:"data"`
}
tmp.Data = NewAttestationData()
if err := json.Unmarshal(buf, &tmp); err != nil {
return err
}
Expand Down
5 changes: 5 additions & 0 deletions cl/phase1/forkchoice/forkchoice_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,3 +220,8 @@ func (f *ForkChoiceStorageMock) OnBlsToExecutionChange(signedChange *cltypes.Sig
func (f *ForkChoiceStorageMock) ForkNodes() []ForkNode {
return f.WeightsMock
}

func (f *ForkChoiceStorageMock) OnAggregateAndProof(aggregateAndProof *cltypes.SignedAggregateAndProof, test bool) error {
f.Pool.AttestationsPool.Insert(aggregateAndProof.Message.Aggregate.Signature(), aggregateAndProof.Message.Aggregate)
return nil
}
1 change: 1 addition & 0 deletions cl/phase1/forkchoice/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type ForkChoiceStorageReader interface {
}

type ForkChoiceStorageWriter interface {
OnAggregateAndProof(aggregateAndProof *cltypes.SignedAggregateAndProof, test bool) error
OnAttestation(attestation *solid.Attestation, fromBlock, insert bool) error
OnAttesterSlashing(attesterSlashing *cltypes.AttesterSlashing, test bool) error
OnVoluntaryExit(signedVoluntaryExit *cltypes.SignedVoluntaryExit, test bool) error
Expand Down
1 change: 1 addition & 0 deletions cmd/devnet/args/node_args.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ type BlockProducer struct {
NodeArgs
Mine bool `arg:"--mine" flag:"true"`
Etherbase string `arg:"--miner.etherbase"`
GasLimit int `arg:"--miner.gaslimit"`
DevPeriod int `arg:"--dev.period"`
BorPeriod int `arg:"--bor.period"`
BorMinBlockSize int `arg:"--bor.minblocksize"`
Expand Down
12 changes: 8 additions & 4 deletions cmd/devnet/devnet/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type Network struct {
Snapshots bool
Nodes []Node
Services []Service
Alloc types.GenesisAlloc
Genesis *types.Genesis
BorStateSyncDelay time.Duration
BorPeriod time.Duration
BorMinBlockSize int
Expand Down Expand Up @@ -140,12 +140,16 @@ func (nw *Network) createNode(nodeArgs Node) (Node, error) {
}

if n.IsBlockProducer() {
if nw.Alloc == nil {
nw.Alloc = types.GenesisAlloc{
if nw.Genesis == nil {
nw.Genesis = &types.Genesis{}
}

if nw.Genesis.Alloc == nil {
nw.Genesis.Alloc = types.GenesisAlloc{
n.Account().Address: types.GenesisAccount{Balance: blockProducerFunds},
}
} else {
nw.Alloc[n.Account().Address] = types.GenesisAccount{Balance: blockProducerFunds}
nw.Genesis.Alloc[n.Account().Address] = types.GenesisAccount{Balance: blockProducerFunds}
}
}

Expand Down
10 changes: 8 additions & 2 deletions cmd/devnet/devnet/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,14 @@ func (n *devnetNode) run(ctx *cli.Context) error {
n.nodeCfg.MdbxGrowthStep = 32 * datasize.MB
n.nodeCfg.MdbxDBSizeLimit = 512 * datasize.MB

for addr, account := range n.network.Alloc {
n.ethCfg.Genesis.Alloc[addr] = account
if n.network.Genesis != nil {
for addr, account := range n.network.Genesis.Alloc {
n.ethCfg.Genesis.Alloc[addr] = account
}

if n.network.Genesis.GasLimit != 0 {
n.ethCfg.Genesis.GasLimit = n.network.Genesis.GasLimit
}
}

if n.network.BorStateSyncDelay > 0 {
Expand Down
69 changes: 65 additions & 4 deletions cmd/devnet/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os/signal"
"path/filepath"
dbg "runtime/debug"
"strconv"
"strings"
"syscall"
"time"
Expand Down Expand Up @@ -131,6 +132,12 @@ var (
Value: 1,
}

GasLimitFlag = cli.Uint64Flag{
Name: "gaslimit",
Usage: "Target gas limit for mined blocks",
Value: 0,
}

WaitFlag = cli.BoolFlag{
Name: "wait",
Usage: "Wait until interrupted after all scenarios have run",
Expand Down Expand Up @@ -173,6 +180,7 @@ func main() {
&logging.LogVerbosityFlag,
&logging.LogConsoleVerbosityFlag,
&logging.LogDirVerbosityFlag,
&GasLimitFlag,
}

if err := app.Run(os.Args); err != nil {
Expand Down Expand Up @@ -342,21 +350,74 @@ func initDevnet(ctx *cli.Context, logger log.Logger) (devnet.Devnet, error) {
baseRpcHost := ctx.String(BaseRpcHostFlag.Name)
baseRpcPort := ctx.Int(BaseRpcPortFlag.Name)
producerCount := int(ctx.Uint(BlockProducersFlag.Name))
gasLimit := ctx.Uint64(GasLimitFlag.Name)

var dirLogLevel log.Lvl = log.LvlTrace
var consoleLogLevel log.Lvl = log.LvlCrit

if ctx.IsSet(logging.LogVerbosityFlag.Name) {
lvlVal := ctx.String(logging.LogVerbosityFlag.Name)

i, err := strconv.Atoi(lvlVal)

lvl := log.Lvl(i)

if err != nil {
lvl, err = log.LvlFromString(lvlVal)
}

if err == nil {
consoleLogLevel = lvl
dirLogLevel = lvl
}
} else {
if ctx.IsSet(logging.LogConsoleVerbosityFlag.Name) {
lvlVal := ctx.String(logging.LogConsoleVerbosityFlag.Name)

i, err := strconv.Atoi(lvlVal)

lvl := log.Lvl(i)

if err != nil {
lvl, err = log.LvlFromString(lvlVal)
}

if err == nil {
consoleLogLevel = lvl
}
}

if ctx.IsSet(logging.LogDirVerbosityFlag.Name) {
lvlVal := ctx.String(logging.LogDirVerbosityFlag.Name)

i, err := strconv.Atoi(lvlVal)

lvl := log.Lvl(i)

if err != nil {
lvl, err = log.LvlFromString(lvlVal)
}

if err == nil {
dirLogLevel = lvl
}
}
}

switch chainName {
case networkname.BorDevnetChainName:
if ctx.Bool(WithoutHeimdallFlag.Name) {
return networks.NewBorDevnetWithoutHeimdall(dataDir, baseRpcHost, baseRpcPort, logger), nil
return networks.NewBorDevnetWithoutHeimdall(dataDir, baseRpcHost, baseRpcPort, gasLimit, logger, consoleLogLevel, dirLogLevel), nil
} else if ctx.Bool(LocalHeimdallFlag.Name) {
heimdallGrpcAddr := ctx.String(HeimdallGrpcAddressFlag.Name)
sprintSize := uint64(ctx.Int(BorSprintSizeFlag.Name))
return networks.NewBorDevnetWithLocalHeimdall(dataDir, baseRpcHost, baseRpcPort, heimdallGrpcAddr, sprintSize, producerCount, logger), nil
return networks.NewBorDevnetWithLocalHeimdall(dataDir, baseRpcHost, baseRpcPort, heimdallGrpcAddr, sprintSize, producerCount, gasLimit, logger, consoleLogLevel, dirLogLevel), nil
} else {
return networks.NewBorDevnetWithRemoteHeimdall(dataDir, baseRpcHost, baseRpcPort, producerCount, logger), nil
return networks.NewBorDevnetWithRemoteHeimdall(dataDir, baseRpcHost, baseRpcPort, producerCount, gasLimit, logger, consoleLogLevel, dirLogLevel), nil
}

case networkname.DevChainName:
return networks.NewDevDevnet(dataDir, baseRpcHost, baseRpcPort, producerCount, logger), nil
return networks.NewDevDevnet(dataDir, baseRpcHost, baseRpcPort, producerCount, gasLimit, logger, consoleLogLevel, dirLogLevel), nil

default:
return nil, fmt.Errorf("unknown network: '%s'", chainName)
Expand Down
Loading

0 comments on commit 63741dd

Please sign in to comment.