Skip to content

Commit f9e4e2d

Browse files
authored
Merge bsp-v2.0.0 to geth-v1.14.12 (#239) (#240)
repatch state-specimen, block-specimen, blob-specimen producer, workflows, linters & docs --------- Signed-off-by: Pranay Valson <[email protected]>
1 parent 26decf3 commit f9e4e2d

29 files changed

+1338
-44
lines changed

Dockerfile

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
1-
# Support setting various labels on the final image
2-
ARG COMMIT=""
3-
ARG VERSION=""
4-
ARG BUILDNUM=""
1+
# # Support setting various labels on the final image
2+
# ARG COMMIT=""
3+
# ARG VERSION=""
4+
# ARG BUILDNUM=""
5+
ARG USER=$USER
6+
57

68
# Build Geth in a stock Go builder container
7-
FROM golang:1.22-alpine AS builder
9+
FROM golang:1.22-alpine as builder
810

911
RUN apk add --no-cache gcc musl-dev linux-headers git
1012

11-
# Get dependencies - will also be cached if we won't change go.mod/go.sum
12-
COPY go.mod /go-ethereum/
13-
COPY go.sum /go-ethereum/
14-
RUN cd /go-ethereum && go mod download
15-
16-
ADD . /go-ethereum
17-
RUN cd /go-ethereum && go run build/ci.go install -static ./cmd/geth
13+
COPY . /go-ethereum
14+
WORKDIR /go-ethereum
15+
RUN go run build/ci.go install -static ./cmd/geth
1816

1917
# Pull Geth into a second stage deploy alpine container
20-
FROM alpine:latest
18+
FROM alpine:3.21
2119

2220
RUN apk add --no-cache ca-certificates
21+
2322
COPY --from=builder /go-ethereum/build/bin/geth /usr/local/bin/
2423

2524
EXPOSE 8545 8546 30303 30303/udp
25+
2626
ENTRYPOINT ["geth", "--mainnet", "--syncmode", "full", "--datadir", "/root/.ethereum/covalent", "--replication.targets", "redis://localhost:6379/?topic=replication", "--replica.result", "true", "--replica.specimen", "true", "--replica.blob", "true"]
2727

28-
# Add some metadata labels to help programmatic image consumption
28+
# Add some metadata labels to help programatic image consumption
2929
ARG COMMIT=""
3030
ARG VERSION=""
3131
ARG BUILDNUM=""

cmd/geth/chaincmd.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ if one is set. Otherwise it prints the genesis from the datadir.`,
102102
utils.VMTraceJsonConfigFlag,
103103
utils.TransactionHistoryFlag,
104104
utils.StateHistoryFlag,
105+
utils.BlockReplicationTargetsFlag,
106+
utils.ReplicaEnableSpecimenFlag,
107+
utils.ReplicaEnableResultFlag,
108+
utils.ReplicaEnableBlobFlag,
105109
}, utils.DatabaseFlags),
106110
Description: `
107111
The import command imports blocks from an RLP-encoded form. The form can be one file
@@ -287,12 +291,15 @@ func importChain(ctx *cli.Context) error {
287291
// Start system runtime metrics collection
288292
go metrics.CollectProcessMetrics(3 * time.Second)
289293

290-
stack, _ := makeConfigNode(ctx)
294+
stack, cfg := makeConfigNode(ctx)
291295
defer stack.Close()
296+
replicators := utils.CreateReplicators(&cfg.Eth)
292297

293298
chain, db := utils.MakeChain(ctx, stack, false)
294299
defer db.Close()
295300

301+
utils.AttachReplicators(replicators, chain)
302+
296303
// Start periodically gathering memory profiles
297304
var peakMemAlloc, peakMemSys atomic.Uint64
298305
go func() {
@@ -327,6 +334,7 @@ func importChain(ctx *cli.Context) error {
327334
}
328335
}
329336
chain.Stop()
337+
utils.DrainReplicators(replicators)
330338
fmt.Printf("Import done in %v.\n\n", time.Since(start))
331339

332340
// Output pre-compaction stats mostly to see the import trashing

cmd/geth/config.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import (
3838
"github.com/ethereum/go-ethereum/common/hexutil"
3939
"github.com/ethereum/go-ethereum/eth/catalyst"
4040
"github.com/ethereum/go-ethereum/eth/ethconfig"
41+
"github.com/ethereum/go-ethereum/internal/ethapi"
4142
"github.com/ethereum/go-ethereum/internal/flags"
4243
"github.com/ethereum/go-ethereum/internal/version"
4344
"github.com/ethereum/go-ethereum/log"
@@ -181,7 +182,7 @@ func makeConfigNode(ctx *cli.Context) (*node.Node, gethConfig) {
181182
}
182183

183184
// makeFullNode loads geth configuration and creates the Ethereum backend.
184-
func makeFullNode(ctx *cli.Context) *node.Node {
185+
func makeFullNode(ctx *cli.Context) (*node.Node, ethapi.Backend) {
185186
stack, cfg := makeConfigNode(ctx)
186187
if ctx.IsSet(utils.OverrideCancun.Name) {
187188
v := ctx.Uint64(utils.OverrideCancun.Name)
@@ -250,7 +251,7 @@ func makeFullNode(ctx *cli.Context) *node.Node {
250251
utils.Fatalf("failed to register catalyst service: %v", err)
251252
}
252253
}
253-
return stack
254+
return stack, backend
254255
}
255256

256257
// dumpConfig is the dumpconfig command.

cmd/geth/consolecmd.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ JavaScript API. See https://geth.ethereum.org/docs/interacting-with-geth/javascr
7070
func localConsole(ctx *cli.Context) error {
7171
// Create and start the node based on the CLI flags
7272
prepare(ctx)
73-
stack := makeFullNode(ctx)
74-
startNode(ctx, stack, true)
73+
stack, backend := makeFullNode(ctx)
74+
startNode(ctx, stack, true, backend)
7575
defer stack.Close()
7676

7777
// Attach to the newly started node and create the JavaScript console.

cmd/geth/main.go

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
"github.com/ethereum/go-ethereum/eth/downloader"
3333
"github.com/ethereum/go-ethereum/ethclient"
3434
"github.com/ethereum/go-ethereum/internal/debug"
35+
"github.com/ethereum/go-ethereum/internal/ethapi"
3536
"github.com/ethereum/go-ethereum/internal/flags"
3637
"github.com/ethereum/go-ethereum/log"
3738
"github.com/ethereum/go-ethereum/metrics"
@@ -155,6 +156,10 @@ var (
155156
utils.BeaconGenesisRootFlag,
156157
utils.BeaconGenesisTimeFlag,
157158
utils.BeaconCheckpointFlag,
159+
utils.BlockReplicationTargetsFlag,
160+
utils.ReplicaEnableResultFlag,
161+
utils.ReplicaEnableSpecimenFlag,
162+
utils.ReplicaEnableBlobFlag,
158163
}, utils.NetworkFlags, utils.DatabaseFlags)
159164

160165
rpcFlags = []cli.Flag{
@@ -342,17 +347,17 @@ func geth(ctx *cli.Context) error {
342347
}
343348

344349
prepare(ctx)
345-
stack := makeFullNode(ctx)
350+
stack, backend := makeFullNode(ctx)
346351
defer stack.Close()
347352

348-
startNode(ctx, stack, false)
353+
startNode(ctx, stack, false, backend)
349354
stack.Wait()
350355
return nil
351356
}
352357

353358
// startNode boots up the system node and all registered protocols, after which
354359
// it starts the RPC/IPC interfaces and the miner.
355-
func startNode(ctx *cli.Context, stack *node.Node, isConsole bool) {
360+
func startNode(ctx *cli.Context, stack *node.Node, isConsole bool, backend ethapi.Backend) {
356361
// Start up the node itself
357362
utils.StartNode(ctx, stack, isConsole)
358363

@@ -401,6 +406,38 @@ func startNode(ctx *cli.Context, stack *node.Node, isConsole bool) {
401406
}
402407
}()
403408

409+
// Kill bsp-geth if --syncmode flag is 'light'
410+
if ctx.String(utils.BlockReplicationTargetsFlag.Name) != "" && ctx.String(utils.SyncModeFlag.Name) == "light" {
411+
utils.Fatalf("Block specimen production not supported for 'light' sync (only supported modes are 'snap' and 'full'")
412+
}
413+
414+
// Spawn a standalone goroutine for status synchronization monitoring,
415+
// if full sync is completed in block specimen creation mode set replica config flag
416+
if ctx.Bool(utils.ReplicaEnableSpecimenFlag.Name) || ctx.Bool(utils.ReplicaEnableResultFlag.Name) {
417+
//log.Info("Synchronisation started, historical blocks synced set to 0")
418+
backend.SetHistoricalBlocksSynced()
419+
420+
go func() {
421+
sub := stack.EventMux().Subscribe(downloader.DoneEvent{})
422+
defer sub.Unsubscribe()
423+
for {
424+
event := <-sub.Chan()
425+
if event == nil {
426+
continue
427+
}
428+
done, ok := event.Data.(downloader.DoneEvent)
429+
if !ok {
430+
continue
431+
}
432+
if timestamp := time.Unix(int64(done.Latest.Time), 0); time.Since(timestamp) < 10*time.Minute {
433+
log.Info("Synchronisation completed, setting historical blocks synced to 1", "latestnum", done.Latest.Number, "latesthash", done.Latest.Hash(),
434+
"age", common.PrettyAge(timestamp))
435+
backend.SetHistoricalBlocksSynced()
436+
}
437+
}
438+
}()
439+
}
440+
404441
// Spawn a standalone goroutine for status synchronization monitoring,
405442
// close the node when synchronization is complete if user required.
406443
if ctx.Bool(utils.ExitWhenSyncedFlag.Name) {

cmd/geth/misccmd.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"strings"
2424

2525
"github.com/ethereum/go-ethereum/internal/version"
26+
"github.com/ethereum/go-ethereum/params"
2627
"github.com/urfave/cli/v2"
2728
)
2829

@@ -73,6 +74,7 @@ func printVersion(ctx *cli.Context) error {
7374

7475
fmt.Println(strings.Title(clientIdentifier))
7576
fmt.Println("Version:", version.WithMeta)
77+
fmt.Println("Bsp Version:", params.BspVersion)
7678
if git.Commit != "" {
7779
fmt.Println("Git Commit:", git.Commit)
7880
}

cmd/utils/flags.go

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"math/big"
2929
"net"
3030
"net/http"
31+
"net/url"
3132
"os"
3233
"path/filepath"
3334
godebug "runtime/debug"
@@ -723,6 +724,23 @@ var (
723724
Value: node.DefaultConfig.BatchResponseMaxSize,
724725
Category: flags.APICategory,
725726
}
727+
BlockReplicationTargetsFlag = &cli.StringFlag{
728+
Name: "replication.targets",
729+
Usage: "Comma separated URLs for message-queue delivery of block specimens",
730+
Value: "",
731+
}
732+
ReplicaEnableSpecimenFlag = &cli.BoolFlag{
733+
Name: "replica.specimen",
734+
Usage: "Enables export of fields that comprise a block-specimen",
735+
}
736+
ReplicaEnableResultFlag = &cli.BoolFlag{
737+
Name: "replica.result",
738+
Usage: "Enables export of fields that comprise a block-result",
739+
}
740+
ReplicaEnableBlobFlag = &cli.BoolFlag{
741+
Name: "replica.blob",
742+
Usage: "Enables export of fields that comprise a block-blob",
743+
}
726744

727745
// Network Settings
728746
MaxPeersFlag = &cli.IntFlag{
@@ -1584,7 +1602,9 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
15841602
setMiner(ctx, &cfg.Miner)
15851603
setRequiredBlocks(ctx, cfg)
15861604
setLes(ctx, cfg)
1587-
1605+
if ctx.IsSet(BlockReplicationTargetsFlag.Name) {
1606+
setBlockReplicationTargets(ctx, cfg)
1607+
}
15881608
// Cap the cache allowance and tune the garbage collector
15891609
mem, err := gopsutil.VirtualMemory()
15901610
if err == nil {
@@ -2245,3 +2265,63 @@ func MakeTrieDatabase(ctx *cli.Context, disk ethdb.Database, preimage bool, read
22452265
}
22462266
return triedb.NewDatabase(disk, config)
22472267
}
2268+
2269+
// setBlockResultTargets creates a list of replication targets from the command line flags.
2270+
func setBlockReplicationTargets(ctx *cli.Context, cfg *eth.Config) {
2271+
var urls []string
2272+
2273+
if ctx.IsSet(BlockReplicationTargetsFlag.Name) {
2274+
urls = strings.Split(ctx.String(BlockReplicationTargetsFlag.Name), ",")
2275+
}
2276+
2277+
cfg.BlockReplicationTargets = make([]string, 0, len(urls))
2278+
for _, urlStr := range urls {
2279+
if urlStr != "" {
2280+
_, err := url.Parse(urlStr)
2281+
if err != nil {
2282+
log.Crit("Replication-target URL invalid", "url", urlStr, "err", err)
2283+
os.Exit(1)
2284+
}
2285+
cfg.BlockReplicationTargets = append(cfg.BlockReplicationTargets, urlStr)
2286+
}
2287+
}
2288+
if ctx.IsSet(ReplicaEnableResultFlag.Name) || ctx.IsSet(ReplicaEnableSpecimenFlag.Name) {
2289+
if ctx.Bool(ReplicaEnableSpecimenFlag.Name) {
2290+
cfg.ReplicaEnableSpecimen = true
2291+
}
2292+
if ctx.Bool(ReplicaEnableResultFlag.Name) {
2293+
cfg.ReplicaEnableResult = true
2294+
}
2295+
if ctx.Bool(ReplicaEnableBlobFlag.Name) {
2296+
cfg.ReplicaEnableBlob = true
2297+
}
2298+
} else {
2299+
Fatalf("--replication.targets flag is invalid without --replica.specimen and/or --replica.result, ONLY ADD --replica.blob with both replica.specimen AND replica.result flags for complete unified state capture)")
2300+
}
2301+
}
2302+
2303+
func CreateReplicators(config *eth.Config) []*core.ChainReplicator {
2304+
replicators := make([]*core.ChainReplicator, 0)
2305+
2306+
for _, blockReplicationTargets := range config.BlockReplicationTargets {
2307+
blockRepl, err := eth.CreateReplicator(blockReplicationTargets)
2308+
if err != nil {
2309+
Fatalf("Can't create replication target: %v", err)
2310+
}
2311+
replicators = append(replicators, blockRepl)
2312+
}
2313+
2314+
return replicators
2315+
}
2316+
2317+
func AttachReplicators(replicators []*core.ChainReplicator, chain *core.BlockChain) {
2318+
for _, replicator := range replicators {
2319+
replicator.Start(chain, chain.ReplicaConfig)
2320+
}
2321+
}
2322+
2323+
func DrainReplicators(replicators []*core.ChainReplicator) {
2324+
for _, replicator := range replicators {
2325+
replicator.Stop()
2326+
}
2327+
}

0 commit comments

Comments
 (0)