Skip to content

Commit

Permalink
remove beacon base options
Browse files Browse the repository at this point in the history
  • Loading branch information
syntrust committed Dec 6, 2024
1 parent 42f754a commit be5d41f
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 32 deletions.
2 changes: 0 additions & 2 deletions cmd/es-node/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,6 @@ func NewL1EndpointConfig(ctx *cli.Context) (*eth.L1EndpointConfig, *ethclient.Cl
L1NodeAddr: l1NodeAddr,
L1BlockTime: ctx.GlobalUint64(flags.L1BlockTime.Name),
L1BeaconURL: ctx.GlobalString(flags.L1BeaconAddr.Name),
L1BeaconBasedTime: ctx.GlobalUint64(flags.L1BeaconBasedTime.Name),
L1BeaconBasedSlot: ctx.GlobalUint64(flags.L1BeaconBasedSlot.Name),
L1BeaconSlotTime: ctx.GlobalUint64(flags.L1BeaconSlotTime.Name),
DAURL: ctx.GlobalString(flags.DAURL.Name),
L1MinDurationForBlobsRequest: ctx.GlobalUint64(flags.L1MinDurationForBlobsRequest.Name),
Expand Down
52 changes: 41 additions & 11 deletions ethstorage/eth/beacon_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ import (
"fmt"
"net/http"
"net/url"
"strconv"

"github.com/crate-crypto/go-proto-danksharding-crypto/eth"
"github.com/ethereum/go-ethereum/common"
)

type BeaconClient struct {
beaconURL string
basedTime uint64
basedSlot uint64
slotTime uint64
beaconURL string
genesisSlotTime uint64
slotTime uint64
}

type Blob struct {
Expand All @@ -41,18 +41,48 @@ type beaconBlobData struct {
KZGProof string `json:"kzg_proof"`
}

func NewBeaconClient(url string, basedTime uint64, basedSlot uint64, slotTime uint64) *BeaconClient {
func NewBeaconClient(url string, slotTime uint64) (*BeaconClient, error) {
genesisSlotTime, err := queryGenesisTime(url)
if err != nil {
return nil, err
}
res := &BeaconClient{
beaconURL: url,
basedTime: basedTime,
basedSlot: basedSlot,
slotTime: slotTime,
beaconURL: url,
genesisSlotTime: genesisSlotTime,
slotTime: slotTime,
}
return res, nil
}

func queryGenesisTime(beaconUrl string) (uint64, error) {
queryUrl, err := url.JoinPath(beaconUrl, "/eth/v1/beacon/genesis")
if err != nil {
return 0, err
}
resp, err := http.Get(queryUrl)
if err != nil {
return 0, err
}
defer resp.Body.Close()

genesisResponse := &struct {
Data struct {
GenesisTime string `json:"genesis_time"`
} `json:"data"`
}{}
err = json.NewDecoder(resp.Body).Decode(&genesisResponse)
if err != nil {
return 0, err
}
gt, err := strconv.ParseUint(genesisResponse.Data.GenesisTime, 10, 64)
if err != nil {
return 0, err
}
return res
return gt, nil
}

func (c *BeaconClient) Timestamp2Slot(time uint64) uint64 {
return (time-c.basedTime)/c.slotTime + c.basedSlot
return (time - c.genesisSlotTime) / c.slotTime
}

func (c *BeaconClient) DownloadBlobs(slot uint64) (map[common.Hash]Blob, error) {
Expand Down
2 changes: 0 additions & 2 deletions ethstorage/eth/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ type L1EndpointConfig struct {
L1NodeAddr string // Address of L1 User JSON-RPC endpoint to use (eth namespace required)
L1BlockTime uint64 // Block time of L1 chain
L1BeaconURL string // L1 beacon chain endpoint
L1BeaconBasedTime uint64 // A pair of timestamp and slot number in the past time
L1BeaconBasedSlot uint64 // A pair of timestamp and slot number in the past time
L1BeaconSlotTime uint64 // Slot duration
DAURL string // Custom DA URL
L1MinDurationForBlobsRequest uint64 // Min duration for blobs sidecars request
Expand Down
14 changes: 0 additions & 14 deletions ethstorage/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,6 @@ var (
Usage: "URL of JSON-RPC endpoint to query randao",
EnvVar: prefixEnvVar("RANDAO_URL"),
}
// TODO: @Qiang everytime devnet changed, we may need to change it
L1BeaconBasedTime = cli.Uint64Flag{
Name: "l1.beacon-based-time",
Usage: "Timestamp of a slot specified by l1.beacon-based-slot",
EnvVar: prefixEnvVar("L1_BEACON_BASED_TIME"),
}
// TODO: @Qiang everytime devnet changed, we may need to change it
L1BeaconBasedSlot = cli.Uint64Flag{
Name: "l1.beacon-based-slot",
Usage: "A slot number in the past time specified by l1.beacon-based-time",
EnvVar: prefixEnvVar("L1_BEACON_BASED_SLOT"),
}
// TODO: @Qiang everytime devnet changed, we may need to change it if the slot time changed
L1BeaconSlotTime = cli.Uint64Flag{
Name: "l1.beacon-slot-time",
Expand Down Expand Up @@ -236,8 +224,6 @@ var optionalFlags = []cli.Flag{
L1BlockTime,
L1BeaconSlotTime,
L1BeaconAddr,
L1BeaconBasedTime,
L1BeaconBasedSlot,
DAURL,
RandaoURL,
L1MinDurationForBlobsRequest,
Expand Down
5 changes: 4 additions & 1 deletion ethstorage/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,10 @@ func (n *EsNode) initL1(ctx context.Context, cfg *Config) error {
n.daClient = eth.NewDAClient(cfg.L1.DAURL)
n.log.Info("Using DA URL", "url", cfg.L1.DAURL)
} else if cfg.L1.L1BeaconURL != "" {
n.l1Beacon = eth.NewBeaconClient(cfg.L1.L1BeaconURL, cfg.L1.L1BeaconBasedTime, cfg.L1.L1BeaconBasedSlot, cfg.L1.L1BeaconSlotTime)
n.l1Beacon, err = eth.NewBeaconClient(cfg.L1.L1BeaconURL, cfg.L1.L1BeaconSlotTime)
if err != nil {
return fmt.Errorf("failed to create L1 beacon source: %w", err)
}
n.log.Info("Using L1 Beacon URL", "url", cfg.L1.L1BeaconURL)
} else {
return fmt.Errorf("no L1 beacon or DA URL provided")
Expand Down
2 changes: 0 additions & 2 deletions run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ start_flags=" --network devnet \
--storage.l1contract 0x804C520d3c084C805E37A35E90057Ac32831F96f \
--l1.rpc http://88.99.30.186:8545 \
--l1.beacon http://88.99.30.186:3500 \
--l1.beacon-based-time 1706684472 \
--l1.beacon-based-slot 4245906 \
--miner.enabled \
--miner.zkey $zkey_file \
--download.thread 32 \
Expand Down

0 comments on commit be5d41f

Please sign in to comment.