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

もろもろの調整を加えた最終系 #86

Merged
merged 49 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from 44 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
2568cf3
support eth67
tak1827 Oct 10, 2024
5577434
secured go.mod
tak1827 Oct 17, 2024
3acdf47
fix compile error
tak1827 Oct 17, 2024
703c752
upgrade wealdtech/go-eth2-types/v2 from v2.5.2 to v2.8.1, to avoid bn…
tak1827 Oct 17, 2024
09ab3c8
downgrade github.com/wealdtech/go-eth2-types to v2.6.0, to kept githu…
tak1827 Oct 17, 2024
24c8643
rever back github.com/herumi/bls-eth-go-binary original version
tak1827 Oct 17, 2024
5a57e88
Merge branch 'feat/v1.13.15' into feat/v1.13.15-compile
tak1827 Oct 20, 2024
84db9b4
integrate bsc cancun support
tak1827 Oct 22, 2024
f801840
Merge branch 'feat/v1.13.15' into feat/v1.13.15-compile
tak1827 Oct 23, 2024
2799d34
Merge branch 'feat/v1.13.15-compile' into feat/v1.13.15-bsc
tak1827 Oct 23, 2024
5580dd3
import bsc PR #2428
tak1827 Oct 23, 2024
139de3f
import bsc PR #2525
tak1827 Oct 23, 2024
b5aa4e2
import bsc PR #2350
tak1827 Oct 23, 2024
8e01409
import bsc PR #2311
tak1827 Oct 23, 2024
884aee6
import bsc PR #2337
tak1827 Oct 23, 2024
138252a
organize ParentBeaconRoot handling
tak1827 Oct 23, 2024
005d784
Merge branch 'feat/v1.13.15' into feat/v1.13.15-compile
tak1827 Oct 24, 2024
77377b7
Merge branch 'feat/v1.13.15-compile' into feat/v1.13.15-bsc
tak1827 Oct 24, 2024
693a117
Merge branch 'feat/v1.13.15-bsc' into feat/v1.13.15-bsc-plus
tak1827 Oct 24, 2024
8a28660
unsupport eth67
tak1827 Oct 24, 2024
9b28506
fix linter error
tak1827 Oct 24, 2024
3f312ef
fix `unexpected withdrawal hash value in oasys`
tak1827 Oct 27, 2024
36766f4
set blob index during commit it
tak1827 Oct 30, 2024
9a0e8d9
add fake beacon api
tak1827 Oct 30, 2024
1d9369b
fix blob freeze bugs
tak1827 Nov 4, 2024
4a3a723
Updated with `gencodec -dir eth/ethconfig/ -type Config -formats toml…
ironbeer Nov 6, 2024
c4d4b3a
Import eth/handler.go from [email protected] (#93)
ironbeer Nov 6, 2024
d6ec6cd
Merge branch 'feat/v1.13.15-bsc' into feat/v1.13.15-bsc-plus
tak1827 Nov 6, 2024
9970144
Update core/blockchain.go
tak1827 Nov 6, 2024
2d7867a
Update core/chain_makers.go
tak1827 Nov 6, 2024
4e4fa3e
respond review by ironbeer part1
tak1827 Nov 6, 2024
cba79ac
Merge branch 'feat/v1.13.15-bsc' of github.com:oasysgames/oasys-valid…
tak1827 Nov 6, 2024
ccb2835
Merge branch 'feat/v1.13.15-bsc' into feat/v1.13.15-bsc-plus
tak1827 Nov 6, 2024
5439006
Restore changes from 4e4fa3e (#95)
ironbeer Nov 6, 2024
f255758
Update params/config.go
tak1827 Nov 6, 2024
54a30fd
Merge branch 'feat/v1.13.15-bsc' into feat/v1.13.15-bsc-plus
tak1827 Nov 6, 2024
9061f5a
fastfinality: incorporate bsc changes ##2589
tak1827 Nov 7, 2024
7add92d
fastfinality: incorporate bsc PR #2568
tak1827 Nov 7, 2024
dd645d0
fix consensus making failure caused by integration of bsc pr #2589
tak1827 Nov 8, 2024
123782f
Import miner/worker.go from [email protected] (2) (#99)
ironbeer Nov 11, 2024
628959f
Merge branch 'feat/v1.13.15-bsc' into feat/v1.13.15-bsc-plus
tak1827 Nov 11, 2024
0a5f3be
Import miner/worker.go from [email protected] (3) (#100)
ironbeer Nov 11, 2024
6bf9928
Merge branch 'feat/v1.13.15-bsc' into feat/v1.13.15-bsc-plus
tak1827 Nov 11, 2024
dfd0f14
Merge branch 'feat/v1.13.15' into feat/v1.13.15-bsc-plus
tak1827 Nov 13, 2024
8d236e6
Dedup of BaseFee field after cancun (#102)
ironbeer Nov 15, 2024
407fdb6
Import blob fee API from [email protected] (#103)
ironbeer Nov 15, 2024
56b03ea
Fixed fakebeacon (#104)
ironbeer Nov 19, 2024
effc835
respond feedback from ironbeer
tak1827 Nov 20, 2024
b4b7266
Merge branch 'feat/v1.13.15-bsc-plus' of github.com:oasysgames/oasys-…
tak1827 Nov 20, 2024
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
87 changes: 87 additions & 0 deletions beacon/fakebeacon/api_func.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package fakebeacon

import (
"context"
"sort"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto/kzg4844"
"github.com/ethereum/go-ethereum/internal/ethapi"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/rpc"
)

type BlobSidecar struct {
Blob kzg4844.Blob `json:"blob"`
Index int `json:"index"`
KZGCommitment kzg4844.Commitment `json:"kzg_commitment"`
KZGProof kzg4844.Proof `json:"kzg_proof"`
}

type APIGetBlobSidecarsResponse struct {
Data []*BlobSidecar `json:"data"`
}

type ReducedGenesisData struct {
GenesisTime string `json:"genesis_time"`
}

type APIGenesisResponse struct {
Data ReducedGenesisData `json:"data"`
}

type ReducedConfigData struct {
SecondsPerSlot string `json:"SECONDS_PER_SLOT"`
}

type IndexedBlobHash struct {
Index int // absolute index in the block, a.k.a. position in sidecar blobs array
Hash common.Hash // hash of the blob, used for consistency checks
}

func configSpec() ReducedConfigData {
return ReducedConfigData{SecondsPerSlot: "1"}
}

func beaconGenesis() APIGenesisResponse {
return APIGenesisResponse{Data: ReducedGenesisData{GenesisTime: "0"}}
}

func beaconBlobSidecars(ctx context.Context, backend ethapi.Backend, slot uint64, indices []int) (APIGetBlobSidecarsResponse, error) {
var blockNrOrHash rpc.BlockNumberOrHash
header, err := fetchBlockNumberByTime(ctx, int64(slot), backend)
if err != nil {
log.Error("Error fetching block number", "slot", slot, "indices", indices)
return APIGetBlobSidecarsResponse{}, err
}
sideCars, err := backend.GetBlobSidecars(ctx, header.Hash())
if err != nil {
log.Error("Error fetching Sidecars", "blockNrOrHash", blockNrOrHash, "err", err)
return APIGetBlobSidecarsResponse{}, err
}
sort.Ints(indices)
fullBlob := len(indices) == 0
res := APIGetBlobSidecarsResponse{}
idx := 0
curIdx := 0
for _, sideCar := range sideCars {
for i := 0; i < len(sideCar.Blobs); i++ {
//hash := kZGToVersionedHash(sideCar.Commitments[i])
if !fullBlob && curIdx >= len(indices) {
break
}
if fullBlob || idx == indices[curIdx] {
res.Data = append(res.Data, &BlobSidecar{
Index: idx,
Blob: sideCar.Blobs[i],
KZGCommitment: sideCar.Commitments[i],
KZGProof: sideCar.Proofs[i],
})
curIdx++
}
idx++
}
}

return res, nil
}
88 changes: 88 additions & 0 deletions beacon/fakebeacon/handlers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package fakebeacon

import (
"fmt"
"net/http"
"net/url"
"strconv"
"strings"

"github.com/prysmaticlabs/prysm/v5/api/server/structs"
field_params "github.com/prysmaticlabs/prysm/v5/config/fieldparams"
"github.com/prysmaticlabs/prysm/v5/network/httputil"
)

var (
versionMethod = "/eth/v1/node/version"
specMethod = "/eth/v1/config/spec"
genesisMethod = "/eth/v1/beacon/genesis"
sidecarsMethodPrefix = "/eth/v1/beacon/blob_sidecars/{slot}"
)

func VersionMethod(w http.ResponseWriter, r *http.Request) {
resp := &structs.GetVersionResponse{
Data: &structs.Version{
Version: "",
},
}
httputil.WriteJson(w, resp)
}

func SpecMethod(w http.ResponseWriter, r *http.Request) {
httputil.WriteJson(w, &structs.GetSpecResponse{Data: configSpec()})
}

func GenesisMethod(w http.ResponseWriter, r *http.Request) {
httputil.WriteJson(w, beaconGenesis())
}

func (s *Service) SidecarsMethod(w http.ResponseWriter, r *http.Request) {
indices, err := parseIndices(r.URL)
if err != nil {
httputil.HandleError(w, err.Error(), http.StatusBadRequest)
return
}
segments := strings.Split(r.URL.Path, "/")
slot, err := strconv.ParseUint(segments[len(segments)-1], 10, 64)
if err != nil {
httputil.HandleError(w, "not a valid slot(timestamp)", http.StatusBadRequest)
return
}

resp, err := beaconBlobSidecars(r.Context(), s.backend, slot, indices)
if err != nil {
httputil.HandleError(w, err.Error(), http.StatusBadRequest)
return
}
httputil.WriteJson(w, resp)
}

// parseIndices filters out invalid and duplicate blob indices
func parseIndices(url *url.URL) ([]int, error) {
rawIndices := url.Query()["indices"]
indices := make([]int, 0, field_params.MaxBlobsPerBlock)
invalidIndices := make([]string, 0)
loop:
for _, raw := range rawIndices {
ix, err := strconv.Atoi(raw)
if err != nil {
invalidIndices = append(invalidIndices, raw)
continue
}
if ix >= field_params.MaxBlobsPerBlock {
invalidIndices = append(invalidIndices, raw)
continue
}
for i := range indices {
if ix == indices[i] {
continue loop
}
}
indices = append(indices, ix)
}

if len(invalidIndices) > 0 {
return nil, fmt.Errorf("requested blob indices %v are invalid", invalidIndices)
}
return indices, nil
}
97 changes: 97 additions & 0 deletions beacon/fakebeacon/server.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package fakebeacon

import (
"net/http"
"strconv"

"github.com/ethereum/go-ethereum/internal/ethapi"
"github.com/gorilla/mux"
"github.com/prysmaticlabs/prysm/v5/api/server"
)

const (
DefaultAddr = "localhost"
DefaultPort = 8686
)

type Config struct {
Enable bool
Addr string
Port int
}

func defaultConfig() *Config {
return &Config{
Enable: false,
Addr: DefaultAddr,
Port: DefaultPort,
}
}

type Service struct {
cfg *Config
router *mux.Router
backend ethapi.Backend
}

func NewService(cfg *Config, backend ethapi.Backend) *Service {
cfgs := defaultConfig()
if cfg.Addr != "" {
cfgs.Addr = cfg.Addr
}
if cfg.Port > 0 {
cfgs.Port = cfg.Port
}

s := &Service{
cfg: cfgs,
backend: backend,
}
router := s.newRouter()
s.router = router
return s
}

func (s *Service) Run() {
_ = http.ListenAndServe(s.cfg.Addr+":"+strconv.Itoa(s.cfg.Port), s.router)
}

func (s *Service) newRouter() *mux.Router {
r := mux.NewRouter()
r.Use(server.NormalizeQueryValuesHandler)
for _, e := range s.endpoints() {
r.HandleFunc(e.path, e.handler).Methods(e.methods...)
}
return r
}

type endpoint struct {
path string
handler http.HandlerFunc
methods []string
}

func (s *Service) endpoints() []endpoint {
return []endpoint{
{
path: versionMethod,
handler: VersionMethod,
methods: []string{http.MethodGet},
},
{
path: specMethod,
handler: SpecMethod,
methods: []string{http.MethodGet},
},
{
path: genesisMethod,
handler: GenesisMethod,
methods: []string{http.MethodGet},
},
{
path: sidecarsMethodPrefix,
handler: s.SidecarsMethod,
methods: []string{http.MethodGet},
},
}
}
65 changes: 65 additions & 0 deletions beacon/fakebeacon/utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package fakebeacon

import (
"context"
"errors"
"fmt"
"math/rand"
"time"

"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/internal/ethapi"
"github.com/ethereum/go-ethereum/rpc"
)

func fetchBlockNumberByTime(ctx context.Context, ts int64, backend ethapi.Backend) (*types.Header, error) {
// calc the block number of the ts.
currentHeader := backend.CurrentHeader()
blockTime := int64(currentHeader.Time)
if ts > blockTime {
return nil, errors.New("time too large")
}
blockNum := currentHeader.Number.Uint64()
estimateEndNumber := int64(blockNum) - (blockTime-ts)/5
// find the end number
for {
header, err := backend.HeaderByNumber(ctx, rpc.BlockNumber(estimateEndNumber))
if err != nil {
time.Sleep(time.Duration(rand.Int()%180) * time.Millisecond)
continue
}
if header == nil {
estimateEndNumber -= 1
time.Sleep(time.Duration(rand.Int()%180) * time.Millisecond)
continue
}
headerTime := int64(header.Time)
if headerTime == ts {
return header, nil
}

// let the estimateEndNumber a little bigger than real value
if headerTime > ts+12 {
estimateEndNumber -= (headerTime - ts) / 5
} else if headerTime < ts {
estimateEndNumber += (ts-headerTime)/5 + 1
} else {
// search one by one
for headerTime >= ts {
header, err = backend.HeaderByNumber(ctx, rpc.BlockNumber(estimateEndNumber-1))
if err != nil {
time.Sleep(time.Duration(rand.Int()%180) * time.Millisecond)
continue
}
headerTime = int64(header.Time)
if headerTime == ts {
return header, nil
}
estimateEndNumber -= 1
if headerTime < ts { //found the real endNumber
return nil, fmt.Errorf("block not found by time %d", ts)
}
}
}
}
}
21 changes: 17 additions & 4 deletions cmd/geth/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"github.com/ethereum/go-ethereum/accounts/keystore"
"github.com/ethereum/go-ethereum/accounts/scwallet"
"github.com/ethereum/go-ethereum/accounts/usbwallet"
"github.com/ethereum/go-ethereum/beacon/fakebeacon"
"github.com/ethereum/go-ethereum/cmd/utils"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
Expand Down Expand Up @@ -92,10 +93,11 @@ type ethstatsConfig struct {
}

type gethConfig struct {
Eth ethconfig.Config
Node node.Config
Ethstats ethstatsConfig
Metrics metrics.Config
Eth ethconfig.Config
Node node.Config
Ethstats ethstatsConfig
Metrics metrics.Config
FakeBeacon fakebeacon.Config
}

func loadConfig(file string, cfg *gethConfig) error {
Expand Down Expand Up @@ -215,6 +217,17 @@ func makeFullNode(ctx *cli.Context) (*node.Node, ethapi.Backend) {
if cfg.Ethstats.URL != "" {
utils.RegisterEthStatsService(stack, backend, cfg.Ethstats.URL)
}

if ctx.IsSet(utils.FakeBeaconAddrFlag.Name) {
cfg.FakeBeacon.Addr = ctx.String(utils.FakeBeaconAddrFlag.Name)
}
if ctx.IsSet(utils.FakeBeaconPortFlag.Name) {
cfg.FakeBeacon.Port = ctx.Int(utils.FakeBeaconPortFlag.Name)
}
if cfg.FakeBeacon.Enable || ctx.IsSet(utils.FakeBeaconEnabledFlag.Name) {
go fakebeacon.NewService(&cfg.FakeBeacon, backend).Run()
}

// Configure full-sync tester service if requested
if ctx.IsSet(utils.SyncTargetFlag.Name) {
hex := hexutil.MustDecode(ctx.String(utils.SyncTargetFlag.Name))
Expand Down
Loading