Skip to content
This repository was archived by the owner on Oct 25, 2024. It is now read-only.

Bring BOR into builder (trial) #124

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ GOBIN = ./build/bin
GO ?= latest
GORUN = env GO111MODULE=on go run

bor:
mkdir -p $(GOPATH)/bin/
go build -o $(GOBIN)/bor $(GO_LDFLAGS) ./cmd/cli/main.go
cp $(GOBIN)/bor $(GOPATH)/bin/
@echo "Done building."

geth:
$(GORUN) build/ci.go install ./cmd/geth
@echo "Done building."
Expand Down
1 change: 1 addition & 0 deletions accounts/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const (
MimetypeDataWithValidator = "data/validator"
MimetypeTypedData = "data/typed"
MimetypeClique = "application/x-clique-header"
MimetypeBor = "application/x-bor-header"
MimetypeTextPlain = "text/plain"
)

Expand Down
11 changes: 11 additions & 0 deletions cmd/cli/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package main

import (
"os"

"github.com/ethereum/go-ethereum/internal/cli"
)

func main() {
os.Exit(cli.Run(os.Args[1:]))
}
3 changes: 3 additions & 0 deletions common/flags/milestone.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package flags

const Milestone = true
5 changes: 5 additions & 0 deletions common/gererics/empty.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package gererics

func Empty[T any]() (t T) {
return
}
36 changes: 36 additions & 0 deletions common/network/port.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package network

import (
"errors"
"fmt"
"net"
)

const (
maxPortCheck = 100

emptyPort = "127.0.0.1:0"
)

var (
ErrCantFindAPort = errors.New("no available port found")
)

// FindAvailablePort returns the an available port
func FindAvailablePort() (int, net.Listener, error) {
var (
listener net.Listener
err error
)

for i := uint(0); i < maxPortCheck; i++ {
listener, err = net.Listen("tcp", emptyPort)
if err != nil {
continue
}

return listener.Addr().(*net.TCPAddr).Port, listener, nil
}

return 0, nil, fmt.Errorf("%w: %s", ErrCantFindAPort, err)
}
11 changes: 11 additions & 0 deletions common/set/slice.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package set

func New[T comparable](slice []T) map[T]struct{} {
m := make(map[T]struct{}, len(slice))

for _, el := range slice {
m[el] = struct{}{}
}

return m
}
102 changes: 102 additions & 0 deletions common/tracing/context.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package tracing

import (
"context"
"time"

"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/trace"
)

type tracerKey struct{}

type Option func(context.Context, trace.Span)

func WithTracer(ctx context.Context, tr trace.Tracer) context.Context {
return context.WithValue(ctx, tracerKey{}, tr)
}

func FromContext(ctx context.Context) trace.Tracer {
tr, _ := ctx.Value(tracerKey{}).(trace.Tracer)

return tr
}

func StartSpan(ctx context.Context, snapName string) (context.Context, trace.Span) {
tr := FromContext(ctx)

if tr == nil {
return ctx, nil
}

ctx, span := tr.Start(ctx, snapName)
ctx = WithTracer(ctx, tr)

return ctx, span
}

func EndSpan(span trace.Span) {
if span != nil {
span.End()
}
}

func Trace(ctx context.Context, spanName string) (context.Context, trace.Span) {
tr := FromContext(ctx)

if tr == nil {
return ctx, nil
}

return tr.Start(ctx, spanName)
}

func Exec(ctx context.Context, instrumentationName, spanName string, opts ...Option) {
var span trace.Span

tr := FromContext(ctx)

if tr == nil && len(instrumentationName) != 0 {
tr = otel.GetTracerProvider().Tracer(instrumentationName)
ctx = WithTracer(ctx, tr)
}

if tr != nil {
ctx, span = tr.Start(ctx, spanName)
}

for _, optFn := range opts {
optFn(ctx, span)
}

if tr != nil {
span.End()
}
}

func WithTime(fn func(context.Context, trace.Span)) Option {
return func(ctx context.Context, span trace.Span) {
ElapsedTime(ctx, span, "elapsed", fn)
}
}

func ElapsedTime(ctx context.Context, span trace.Span, msg string, fn func(context.Context, trace.Span)) {
var now time.Time

if span != nil {
now = time.Now()
}

fn(ctx, span)

if span != nil {
span.SetAttributes(attribute.Int(msg, int(time.Since(now).Microseconds())))
}
}

func SetAttributes(span trace.Span, kvs ...attribute.KeyValue) {
if span != nil {
span.SetAttributes(kvs...)
}
}
6 changes: 6 additions & 0 deletions consensus/bor/abi/interface.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package abi

type ABI interface {
Pack(name string, args ...interface{}) ([]byte, error)
UnpackIntoInterface(v interface{}, name string, data []byte) error
}
Loading